Jump to content

Nginx + apache2 = real-ip


Leon
 Share

Recommended Posts

  • Administrators

Nginx and Apache2 are running great but there is only one tiny problem with the visitors ip’s.

 

Normaly I let my nginx instance do the logging job, but if you let your Apache do it you will get some problems. Apache will see all incoming requests as coming from localhost (127.0.0.1). Right they are all from nginx.

 

Solution:

 

# Install rpaf module for Apache2

aptitude install libapache2-mod-rpaf

 

# Enable it

a2enmod rpaf

 

Now add this to your apache.conf or httpd.conf

 

RPAFenable On

RPAFsethostname On

RPAFproxy_ips 127.0.0.1 10.0.0.1

RPAFheader X-Forwarded-For

 

 

# Restart apache2

/etc/init.d/apache2 restart

 

 

This tells Nginx to forward the original remote IP-address in the header as it proxys ro Apache.

Add this 3 Lines to your nginx.conf or to your enables site config:

 

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...