WordPress NGINX configuration solve gateway timeout


You facing NGINX gateway timeout in wordpress. You already change php.ini and increase timeout but not solve the problem yet. Also, you increase timeout in HAProxy and not results yet. Then the problem come inside NGINX. Some cases it’s happen because Fast CGI timeout is so tight. Also, it because client response timeout also small.

Here are example how to increasing timeout in NGINX for our WordPress :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
server {
         server_name wpscale.com;
         rewrite ^ http://www.wpscale.com$request_uri? permanent;
}

server {
        listen   80;
        server_name www.wpscale.com;
        root    <YOUR_PATH_HERE>

        client_body_timeout  160;
        client_header_timeout 160;
        send_timeout 160;
        client_max_body_size 10m;

        access_log  /var/log/nginx/access.log;
        index  index.php index.html index.htm;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content
                try_files $uri $uri/ /index.php?$args;
        }


        # Add trailing slash to */wp-admin requests.
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
                fastcgi_send_timeout 1800;
                fastcgi_read_timeout 1800;
                fastcgi_connect_timeout 1800;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

        # deny access to .htaccess files, if Apache document root
        # concurs with nginx one
        #
        location ~ /.ht {
                deny  all;
        }
}

Now restart your NGINX services and check if there still gateway timeout or not. 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.