nginx – setup as reverse proxy

 

Previously to take down this wordpress site all you needed to do was hold down F5 for about 20 seconds then the site would take about 5 mins to recover.

There were a few factors causing this and quite a few different methods to solving the problem. WordPress itself is run on php / apache, apache has an evasive mod which can block certain IPs depending on the defined abusive behavior (typical DDOS attack). Since i like to run a few websites behind a single IP i looked at fixing the issue closer to the perimeter….

Enter nginx (engine x) as a reverse proxy, the site now typically caches all content and serves it straight out of memory. No longer does mysql / apache kill itself under high load on the backend…

nginx

You will need to create the nginx directories if they dont already exist. Check /var/log/nginx/error.log (default ubuntu) if any issues starting the service.

sudo aptitude install nginx
sudo service nginx start

The following added to http {}
(located in /etc/nginx/nginx.conf)


log_format cache '***$time_local '
'$remote_addr '
'$upstream_cache_status '
'Cache-Control: $upstream_http_cache_control '
'Expires: $upstream_http_expires '
'"$request" ($status) ';
access_log /var/log/nginx/access.log cache;
error_log /var/log/nginx/error.log;
server_names_hash_bucket_size 64;
proxy_cache_path /var/www/nginx_cache levels=1:2
keys_zone=one:10m
max_size=1g inactive=30m;
proxy_temp_path /var/www/nginx_temp;

the following added to location / {}
(located in /etc/nginx/sites-enabled/default)


proxy_pass http://sigtar;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering on;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_cache one;
proxy_cache_valid 200 302 304 10m;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
client_body_buffer_size 128k;
proxy_busy_buffers_size 64k;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header Set-Cookie;

Note if you have problems with wordpress redirect issues… check this post;

http://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/

Also confirm you have this line in http {}

server_names_hash_bucket_size 64;

Very basic load test, user load time is reasonably consistent as user count increases.
http://loadimpact.com/load-test/sigtar.com-ad07b7870a75c854a935752b0a032c53

load test

1,335 Replies to “nginx – setup as reverse proxy”

  1. My husband and i have been really comfortable that Chris could finish off his studies using the precious recommendations he grabbed out of your web pages. It is now and again perplexing to simply be releasing secrets and techniques that many the rest might have been selling. And we also fully grasp we have got you to be grateful to for that. The most important illustrations you’ve made, the easy blog navigation, the relationships you will make it possible to create – it’s got many wonderful, and it is aiding our son in addition to our family understand this theme is entertaining, which is certainly especially vital. Thanks for the whole thing!

  2. Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossip and web stuff and this is actually irritating. A good site with interesting content, that’s what I need. Thank you for making this web site, and I’ll be visiting again. Do you do newsletters by email?

  3. Hiya, I am really glad I’ve found this information. Nowadays bloggers publish only about gossip and internet stuff and this is really irritating. A good site with interesting content, this is what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  4. Hey there. I discovered your web site by the use of Google even as looking for a similar matter, your website came up. It seems great. I have bookmarked it in my google bookmarks to visit then.

  5. We absolutely love your blog and find the majority of
    your post’s to be precisely what I’m looking for.
    can you offer guest writers to write content for you? I wouldn’t mind publishing a post or elaborating
    on most of the subjects you write regarding here. Again, awesome
    site!

  6. What’s Happening i am new to this, I stumbled upon this I have discovered It absolutely useful and it has aided me out loads.
    I hope to contribute & aid other users like its aided me.
    Good job.

  7. Hiya, I’m really glad I’ve found this information. Nowadays bloggers publish only about gossip and web stuff and this is actually irritating. A good blog with exciting content, that’s what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  8. Hey there. I found your blog by way of Google at the same time as searching for a comparable topic, your web site came up. It appears to be good. I have bookmarked it in my google bookmarks to come back then.

  9. Hi there. I found your website by the use of Google at the same time as searching for a comparable matter, your website got here up. It seems great. I’ve bookmarked it in my google bookmarks to come back then.

  10. Hiya, I’m really glad I’ve found this information. Today bloggers publish only about gossip and web stuff and this is really annoying. A good website with interesting content, this is what I need. Thanks for making this site, and I will be visiting again. Do you do newsletters by email?

  11. Hiya, I’m really glad I’ve found this info. Today bloggers publish only about gossip and internet stuff and this is really frustrating. A good site with interesting content, that’s what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  12. Hello there. I found your web site by means of Google while looking for a comparable topic, your web site came up. It appears to be great. I’ve bookmarked it in my google bookmarks to come back then.

  13. Hi there. I found your site by means of Google even as searching for a comparable topic, your website got here up. It appears good. I’ve bookmarked it in my google bookmarks to come back then.

  14. Hello there. I found your site by way of Google at the same time as looking for a related topic, your web site got here up. It looks great. I have bookmarked it in my google bookmarks to come back then.

Leave a Reply

Your email address will not be published.