我有一个PHP文件在我的/批处理/文件夹中运行,每小时CRON工作。 不幸的是,这个过程往往需要几分钟的时间才能完成,所以我不得不将fastcgi_read_timeout增加到整个服务器的300秒。
我想知道是否可以改变fastcgi_read_timeout指令只有在我/批/文件夹中的文件,而不是整个服务器。 比如像这样的东西…
location ~ \.php$ { fastcgi_pass localhost:9000; fastcgi_read_timeout 5; location /batch/ { fastcgi_read_timeout 300; } include /usr/local/nginx/conf/fastcgi_params; }
所以基本上服务器上的所有PHP文件都会有5秒的超时,除了我的/批/文件夹中的PHP文件。 这可能吗?
这里的不同之处:
location指令文档,了解如何select服务请求的块。 你可以(你希望)做相反的事情 fastcgi_pass为当前块激活FastCGI反向代理,但不会inheritance(这会是一个混乱!) 你可以使用这样的configuration片段:
location /batch/ { location ~* \.php$ { include /usr/local/nginx/conf/fastcgi_params; fastcgi_read_timeout 300; fastcgi_pass localhost:9000; } } location ~* \.php$ { include /usr/local/nginx/conf/fastcgi_params; fastcgi_read_timeout 5; fastcgi_pass localhost:9000; }
但是请注意,尽pipe(引用文档):[ fastcgi_param指令] 是从前一级inheritance而来的,当且仅当在当前级别上没有定义fastcgi_param指令时。