Geza Turi
Geza Turi

Reputation: 104

Nginx fastcgi_read_timeout at specific location

I would like to increase the fastcgi_read_timeout at location level for nginx. However it doesn't work. The fastcgi_read_timeout is still 6 instead of 10. My config file is :

server {

listen 80;
listen [::]:80;
index index.php;

root /websites/somesite.org;
server_name somesite.org;
fastcgi_read_timeout 6s;

location / {
    try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
    include fastcgi.conf;
    internal;
}

# increase timeout for charity uploads
location = /charities/charities/import/ {
    fastcgi_read_timeout 10s;
    try_files $uri /index.php$is_args$args;
}

# any other php extension should fail
location ~ \.php$ {
    return 403;
}

}

However if I add return 403; in place of fastcgi_read_timeout 10s; it correctly returns 403. What am I doing wrong?

Upvotes: 2

Views: 12307

Answers (1)

M. Hardy
M. Hardy

Reputation: 174

It does not work because the fastcgi_read_timeout directive must either be in the same location as the fastcgi_pass or at the server level.

Hence you should either set it for the whole server block or add the fastcgi_pass directive to the location with the specific timeout.

In your case that would look something like:

# increase timeout for charity uploads
location = /charities/charities/import/ {
    include fastcgi.conf;
    fastcgi_read_timeout 10s;
    fastcgi_pass worker:9000;
}

Of course that depends on the way your PHP script works, maybe you'll need to hard set PHP-FPM's SCRIPT_FILENAME (with fastcgi_param).

Upvotes: 5

Related Questions