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 a magento on a LEMP stack (Nginx, PHP-FPM and Percona).

Every time I click on Edit on the order address, the page is taking a long time to load and then result in 502 Bad Gateway error. There's nothing in the error logs (already checked).

I did notice the following (100% cpu usage on one of the FPM process):

enter image description here

This is my setup so far.


user                    www-data;
worker_processes        2; # Should Match Total Cores Server Has
worker_rlimit_nofile    100000;
error_log               /var/log/nginx/error.log crit;
pid                     /var/run/nginx.pid;

events {
    worker_connections 2048;
    use epoll;
    multi_accept on;

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

    # cache informations about FDs, frequently accessed files can boost performance
    open_file_cache max=200000 inactive=20s; 
    open_file_cache_valid 30s; 
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    # buffer config
    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    large_client_header_buffers 4 16k;
    server_names_hash_bucket_size   64;

    # to boost IO on HDD we can disable access logs
    access_log off;

    # copies data between one FD and other from within the kernel
    # faster then read() + write()
    sendfile on;

    # send headers in one peace, its better then sending them one by one 
    tcp_nopush on;

    # don't buffer data sent, good for small data bursts in real time
    tcp_nodelay on;

    # server will close connection after this time
    keepalive_timeout 15;

    # number of requests client can make over keep-alive
    keepalive_requests 100000;

    # allow the server to close connection on non responding client, this will free up memory
    reset_timedout_connection on;

    # request timed out 
    client_body_timeout 12;
    client_header_timeout 12;

    # if client stop responding, free up memory
    send_timeout 10;

    # reduce the data that needs to be sent over network
    gzip             on;
    gzip_static      on;
    gzip_comp_level  4;
    gzip_min_length  1000;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_types       text/plain application/x-javascript text/xml text/css application/xml;

    # Load vHosts
    include /etc/nginx/conf.d/*.conf;

fastcgi_params buffer specific config

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors off;

www.domain.com.conf virtual host entry

## Nginx php-fpm Upstream - Must Be Named Uniquely Per vHost
upstream wwwdomaincom {
    server unix:/var/run/php-fcgi-www-data.sock;

## Web Server Config
    ## Server Info
    listen 80;
    server_name domain.com *.domain.com;
    root /home/www-data/public_html;
    index index.html index.php;

    ## Error log
    error_log /home/www-data/logs/nginx-errors.log;

    ## DocumentRoot setup
    location / {
        try_files $uri $uri/ @handler;
        expires 30d;

    ## These locations would be hidden by .htaccess normally
    location /app/                       { deny all; }
    location /includes/                  { deny all; }
    location /lib/                       { deny all; }
    location /media/downloadable/        { deny all; }
    location /pkginfo/                   { deny all; }
    location /report/config.xml          { deny all; }
    location /var/                       { deny all; }

    ## Require password for accessing export data
    location /var/export/ {
        auth_basic           "Restricted";
        auth_basic_user_file htpasswd;
        autoindex            on;

    ## Disable .htaccess and other hidden files
    location  /. {
        return 404;

    ## Magento uses a common front handler
    location @handler {
        rewrite / /index.php;

    ## Forward paths like /js/index.php/x.js to relevant handler
    location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
        expires    max;
        add_header Cache-Control public;

    ## Execute PHP scripts
    location ~ \.php$ {
        try_files $uri =        404;
        expires                 off;
        fastcgi_pass            wwwdomaincom;
        fastcgi_param           SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param           MAGE_RUN_CODE default;
        fastcgi_param           MAGE_RUN_TYPE store;
        include                 fastcgi_params;

www-data.conf php-fpm pool


listen = '/var/run/php-fcgi-www-data.sock'
listen.allowed_clients =
listen.backlog = -1
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
user = www-data
group = www-data

pm = static
pm.max_children = 25
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 512

request_terminate_timeout = 30s
request_slowlog_timeout = 30s

rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

slowlog = /home/www-data/logs/www-slow.log

php_admin_value[error_log] = /home/www-data/logs/php-errors.log
php_admin_value[date.timezone] = Europe/London
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = on
php_value[error_reporting] = E_ALL & ~E_DEPRECATED
php_value[memory_limit] = 2048M
php_value[max_execution_time] = 600
php_value[max_input_time] = 600
php_value[post_max_size] = 20M
php_value[upload_max_filesize] = 20M
php_value[session.gc_maxlifetime] = 86400
php_value[session.entropy_length] = 32
php_value[session.entropy_file] = /dev/urandom

So, any idea why I am getting 502 bad gateway error? Is there anything wrong with my server configs? I've tried increasing the timeouts to 10 Minutes and that didn't help either.

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.