My server have 512 MB memory. nginx.conf setting is

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;

http {

# Basic Settings

sendfile on;
#tcp_nopush on;
#tcp_nodelay on;
keepalive_timeout 3;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Logging Settings

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Gzip Settings

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Virtual Host Configs
upstream php {

open_file_cache max=5000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

my php fpm config is

user = www-data
group = www-data
pm = dynamic

pm.max_children = 50

pm.start_servers = 25

pm.min_spare_servers = 8

pm.max_spare_servers = 40

I am using one wordpress site. But it's too slow. I have another 512 MB server for the office. It's using apache and it's more faster than nginx + phpfpm. Is there anything wrong in my configuration ?

Memory usages

memory free

Top results

top results


3 Answers 3


dont start so many php servers initially, perhaps consider testing without this block of code too:

open_file_cache max=5000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;

it looks to me like your trying to load too much into ram initially with php though, it also sounds like your website is a little resource intensive based on the memory usage in top, have you considered an opcode cacher like APC? http://pecl.php.net/APC


I use a similar setup with nginx and php-fpm with APC. The Min and Max Servers are a bit high, I also have a virtual machine with about 500mb of memory per machine. After reading https://stephentanner.com/tuning-php-fpm.html I've tuned my machines to the following.

pm.max_children = 6
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 50

My machines sit with 4 php-fpm processes at about 60mb each eating about 252mb which leaves more resources for nginx/mysql/whatnot.

Give that a try if it doesn't fit your need exactly tune it a bit more.

  • yes, this is quite important, if you have a smallish server (say amazon micro) you will get terrible performance with default configuration. the above config is decent for a tiny server. (1ghz cpu / 512mb ram)
    – Edward
    Commented Jul 4, 2018 at 14:07

I'm a bit unsure why you're doing inline gz compression, this takes CPU cycles.. why do you need it?

As anthonysomerset said, lower the number of php children.

  • Compression takes almost no time on PCs newer than 15 years.
    – demonkoryu
    Commented Jul 8, 2013 at 10:06
  • Also with 2000-3000 conns/sec?
    – Marki555
    Commented Feb 10, 2014 at 20:47

You must log in to answer this question.

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