Nginx fastcgi_read_timeout在特定位置

时间:2018-02-12 21:00:13

标签: nginx nginx-location

我想在nginx的位置级别增加fastcgi_read_timeout。但它不起作用。 fastcgi_read_timeout仍然是6而不是10.我的配置文件是:

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;
}

}

但是如果我添加返回403;代替fastcgi_read_timeout 10s;它正确地返回403.我做错了什么?

1 个答案:

答案 0 :(得分:0)

它不起作用,因为fastcgi_read_timeout指令必须与locationfastcgi_pass级别在同一server

因此,您应该为整个server块设置它,或者将fastcgi_pass指令添加到具有特定超时的location

在你的情况下看起来像:

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

当然这取决于你的PHP脚本的工作方式,也许你需要硬设置PHP-FPM的SCRIPT_FILENAMEfastcgi_param)。