Report this

What is the reason for this report?

Regarding to way of Nginx server's optimization

Posted on January 26, 2015

Hi Im looking for a way of Nginx server’s Optimization. Although I tried to read article in here and google it. I dont know which methods are better because of variety configration. If there is good instruction plz let me know! THANKS!



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!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @EpicCDN:

@junukseo that tutorial seems ok, but it only covers nginx, as i’m guessing here I bet you run php on your sites too (they are not 100% static websites made of html files right?), if this is the case you need to optimize php manager, which again i’m assuming it should be php-fpm?

If it is php-fpm open the config file (maybe in /etc/php-fpm.d/www.conf it varies by OS), there you may check this parameters:

This is just an example, don’t use the same values (more below) pm = dynamic pm.max_children = 128 pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 15 pm.max_requests = 500

Where pm=dynamic is maybe the best option for most servers. pm.max_children = 128 is the amount of processes your server will handle at the same time, each process or children can handle several connections so this not need to be too high unless you are expecting too many visitors at the same time, and you have the resources for it.

so to start try pm.max_children = 64 and go up if need it.

pm.start_servers = 2 pm.min_spare_servers = 2 pm.max_spare_servers = 4

in theory you should set pm.max_spare_servers to the number of cores your server has, or so they say, in your case 1, but you can try adjust a little bit higher, try 4+, and see how it works,

start and min_spare servers are the number of servers you want to start with, try a low value like 2 to start with.

PHP is the slowest process in your webserver, so the most you optimize the better. but you need to test it to be sure, you can use ab to stress test, but I suggest you to open a free account at blitz.io, if you open a free account at Cloudflare (which you should) you get a free account with blitz.io that allows you to stress test your site up to 250 concurrent visitors for a few seconds, which is good to know how many users your server can handle.

Play with pm.max_children and pm.max_spare_servers till you can handle most of the 250 concurrent visitors from blitz.io stress test. Also make sure to use Cloudflare service, it will handle most of the load off your server.

note: Blitz.io free account is on apps section in the Cloudflare panel.

Best of lucks

View the original comment

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.