Nginx and PHP FPM is slow

nginxphp-fpm

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 {
    server 127.0.0.1:9000;
}


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

Best Answer

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