Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have recently shifted to a 2 server setup where Nginx, Apache Fastcgi and Php-fpm sit on one server while Mysql 5.5 on another. Each server has a RAM on 1GB

Nginx is used as an image proxy to Apache. And apache communicates with Php-Fpm over a socket using FastCgi.

Apache is using MPM worker config (i use the following config)

<IfModule mpm_worker_module>
    StartServers         2
    ServerLimit          2
     MinSpareThreads      50
    MaxSpareThreads      80
    ThreadLimit          80
    ThreadsPerChild      50
    MaxClients           100
    MaxRequestsPerChild  10000

Nginx basic config

user                www-data www-data;
worker_processes    2;

events {
  worker_connections  1024;
  use epoll; 
server_tokens       off;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;

keepalive_timeout   55;

Now when i carry out load tests using both ab and Siege i get a large difference in transactions per seconds between the 2 tools

at times abs gives very poor results with a 3-6 trans per secs and siege return results with 22-26 trans per second

I am a little confused here, unable to decide if my new setup has improved performance or not!!.

Previously when i used to test i use to get 3-6 trans per sec on an avg which was low but when siege start giving results of 26 trans per sec i was convinced.

nginx.conf settings

client_header_timeout 30m;
client_body_timeout 30m;
send_timeout 30m;
connection_pool_size 256;
client_header_buffer_size 16k;
client_max_body_size 24M;
client_body_buffer_size 128k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
proxy_buffer_size   256k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   128k;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 1m;
fastcgi_buffers 4 500k;
fastcgi_busy_buffers_size 1m;
fastcgi_temp_file_write_size 1m;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
output_buffers 1 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 2;
ignore_invalid_headers on;
share|improve this question

1 Answer 1

There is probably no need for apache here at all, unless your app is specifically using apache APIs. Just serve images with nginx, and have it pass the rest to PHP-FPM directly; you'll get MUCH better performance.

Also, assuming a small PHP script of 8MB, your 100 maxclients = 100 x 8MB = 800MB just for PHP, which will kill a small VPS. That's BEFORE considering memory required for a database and so on. If you're running something big with PHP, like drupal (with a lot of plugins) or magento, that could be more 100 clients x 200MB = 20GB of memory required. Most wordpress installs are more like 16-32MB, so you're in the area of 2GB memory required, plus database, nginx, etc.

Probably what you're seeing here is benchmarks varying according to when your server runs out of memory and starts grinding to a halt due to swapping. I'd suggest starting with a nice clean nginx + fpm config, finding out how much RAM one PHP thread uses maximum after using your app for a while, then tuning nginx / fpm and your DB accordingly. Frankly, these days, just uninstall apache, if you can.

share|improve this answer
i considered that initially but my application depends on ejabberd and http-polling a lot, and some how what ever I tried just did not work with Nginx. Hence I decided to make Nginx just act as a proxy to handle images to decrease the load on apache and let apache deal with the http polling and pass php to php-fpm. Does nginx work with ejabberd and http-polling –  sheldon Nov 4 '11 at 16:02
I managed to successfully set up nginx with http polling, and my system was working smoothly when all of a sudden i started getting 502 gad gateway erros. I have attach the configuration i am using what am i doing wrong –  sheldon Nov 4 '11 at 20:18
I finally took your advice and have shifted completely to nginx no apache anymore. After hours of fire fighting managed to get things to work successfully. Just needed some more advice on what settings should be good for a nginx and php-fpm setup of a 4core dual processer having 1GB RAM. My application is currently on a rackspace cloud nginx and php-fpm are one 1 instance and mysql on another instance. thanks for the advice! –  sheldon Nov 5 '11 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.