2017-02-27 31 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).