2017-02-27 27 views
1

有“繁重”页面需要更多时间加载。 示例页面url:http://example.com/index.php?task=update&action=map(几个参数)。Nginx,条件更改参数

我期待下面的nginx的配置(/etc/nginx/sites-available/default):

server { 
    #... 
    location ~ \.php$ { 
     set $isMap ""; 
     if ($arg_task = update) { set $isMap 1$isMap; } 
     if ($arg_action = map) { set $isMap 1$isMap; } 
     if ($isMap = 11) { 
      fastcgi_read_timeout 600; 
     }  
    } 
} 

但我得到了一个错误: "fastcgi_read_timeout" directive is not allowed here

如何更改超时特定页面(网址具有参数)?

回答

1

TL; DR:从不在if块中使用fastcgi_ *和proxy_ *指令。

每一个FastCGI配置变种创建单独的指定位置,并重定向到它

location ~ \.php$ { 
    ... 
    if(...) { 
    error_page 418 = @fastcgi_1; 
    return 418; 
    } 
} 

location @fastcgi_1 { 
    fastcgi_read_timeout 600; 
    fastcgi_pass 127.0.0.1:9000; 
} 

你应该对细节读http://agentzh.blogspot.ru/2011/03/how-nginx-location-if-works.html

Okay, you see how ngx_proxy module's config inheritance among nested locations take the key role here, and make you believe it works the way that you want. But other modules (like echo mentioned in one of my earlier emails) may not inherit content handlers in nested locations (in fact, most content handler modules, including upstream ones, don't).