0

On my server I have installed Varnish in front of nginx, to serve static files faster. When using my site I have found following bug: Every comment on my wordpress blog is coming from localhost (127.0.0.1) and nobody is now allowed to write comments (wordpress is blocking too much comments from one ip). How can I make comments to be posted to nginx (wordpress) with their original ip, or how can I disable comments lockdown?

1
  • 1
    nginx is just as fast as Varnish when it comes down to serving static files.
    – alexus
    Jul 21, 2014 at 20:52

1 Answer 1

0

Commenter is right, nginx is just as fast as varnish at serving up static files. There's often not a reason to have the 2 in tandem, except in certain circumstances (when using advanced full page caching, ESI, etc).

To answer your question directly, you'll need to do some tinkering within Wordpress itself to get it to discover the real IP. It's a bit of a hack, but since Wordpress is full of them, it should be fine (and I've done this many times before in production with success).

In your wp-config.php file, somewhere (near the top is good) put;

$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

This is under the assumption that your Varnish server is sending the X-Forwarded-For header. Instructions how to do this if it doesn't already can be found here.

This fools Wordpress into believing that whatever the IP is sent by the proxy is the real user's IP. In most cases this is safe, some people would worry that headers are too easy to spoof, however if you have a reverse proxy that explicity defines that header (read: overwrites anything that might be incoming with the correct value), it will be fine.

Hope this helps.

2
  • Thank you, but how nginx can be as-fast-as varnish in serving static files? Nginx does not use RAM to serve static files and varnish do. I have a site with many images and am i not right when i'm thinking that varnish will be better to handle those files? I have 10GB of free RAM, so boost like that would be very helpfull " if you have a reverse proxy that explicity defines that header (read: overwrites anything that might be incoming with the correct value), it will be fine." And if I have varnish in front of nginx, would it be fine?
    – Guest
    Jul 23, 2014 at 15:21
  • You can make nginx work as a remote caching proxy, with almost the same performance as varnish under moderate load. Main problems with that approach is lack of features (eg ESI), hard to configure (because nginx is mainly a web server) and lack of support functions (advanced logging, counters, "top" etc etc).
    – Clarence
    Jul 24, 2014 at 13:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .