Nginx 仅当 url 中包含特定参数时才设置 proxy_send_timeout

Saj*_*jid 2 timeout nginx

我是 nginx 的新手,现在正在学习它:),我需要一些设置 proxy_send_timeout 的帮助,只有当 url 在代理中有“stime”时我才需要设置它,这就是我正在做的事情:

if ($arg_stime != ""){
  proxy_send_timeout 15;
  proxy_read_timeout 15;
}
Run Code Online (Sandbox Code Playgroud)

但 nginx 无法启动并给出以下错误:

4901#0:default.conf 中不允许使用“proxy_send_timeout”指令

任何建议,谢谢

此致

萨吉德

Ale*_*Ten 5

您不能在内部使用proxy_read_timeout/ ,但有解决方法。proxy_send_timeoutif

\n\n

这是示例代码:

\n\n
server {\n    # ...\n\n    error_page 555 = @normal;\n    error_page 556 = @stime;\n\n    location / {\n        if ($arg_stime != \'\') {\n            return 556;\n        }\n        return 555;\n    }\n\n    location @normal {\n        proxy_pass ...;\n        # ...other proxy directives...\n    }\n\n    location @stime {\n        proxy_pass ...;\n        # ...other proxy directives...\n        proxy_send_timeout 15s;\n        proxy_read_timeout 15s;\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

我们使用 \xe2\x80\x9c If is Evil \xe2\x80\x9d中的想法来选择location将处理我们的请求。

\n