Regarding to way of Nginx server's optimization

January 26, 2015 4.4k views

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!

7 comments
  • There are many ways, and most depend of your own needs. Nginx by itself is pretty fast so not much optimization is needed, php-fpm may need some tweaks for sure, but are also simple. maybe you can share more info about your setup, application, and conf files, as same for your expectations for it.

  • @EpicCDN

    Hi. Thanks for your reply. I'm using LEMP server with 5dollor plan and i just optimized refer to https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration this article.

    I keep another setting as default and I'm operating 2websites using server blocks. Would you tell me how to set up nginx server?
    many thanks

    by Alex Kavon
    Nginx is a fast and lightweight alternative to the sometimes overbearing Apache 2. However, Nginx just like any kind of server or software must be tuned to help attain optimal performance. Here's how to optimize Nginx configuration.
  • @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.maxchildren = 128
    pm.start
    servers = 2
    pm.minspareservers = 2
    pm.maxspareservers = 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.startservers = 2
    pm.min
    spareservers = 2
    pm.max
    spare_servers = 4

    in theory you should set pm.maxspareservers 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.maxchildren and pm.maxspare_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

  • @EpicCDN

    Thanks for your reply.

    I set up all configration as you showed me and tested at Blitz.io.

    I really appreciate to you

    and I have one more question.

    I am using Cloudflare + LENP with Configration + Fast cgi

    I'm not using any Cache plugin in Wordpress.

    Could you tell me what cache plugins or modules do you recommend?

  • Show 3 more comments
1 Answer

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.maxchildren = 128
pm.start
servers = 2
pm.minspareservers = 2
pm.maxspareservers = 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.startservers = 2
pm.min
spareservers = 2
pm.max
spare_servers = 4

in theory you should set pm.maxspareservers 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.maxchildren and pm.maxspare_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

Have another answer? Share your knowledge.