By toyen
Hi DO Community,
I have 2 droplet,
serverA - varnish serverB - LAMP (wordpress)
My LAMP show serverA private IP instead of real client IP. How I can get real client IP in this situation?
Thank you.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
In order to have Varnish pass on the real client IP to your Apache access log, you’ll need to edit your Varnish configuration (/etc/varnish/default.vcl on Ubuntu) to add an X-Forwarded-For header. Find the vcl_recv section and added the following:
sub vcl_recv {
unset req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
}
(Note: If you are using Varnish < 4.0 change unset to remove as the syntax is different.)
Than, in your Apache Virtual Host, set a CustomLog format:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{User-agent}i\"" varnishcombined
CustomLog ${APACHE_LOG_DIR}/access.log varnishcombined
Finally, restart both Apache and Varnish for the changes to take effect:
sudo service varnish restart
sudo service apache2 restart
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.