ReWriteRule 代理超时

dav*_*rez 4 apache proxy timeout

使用 Apache 2.4 通过 ReWriteRule (mod_rewrite) 进行代理时,无法控制超时。

<VirtualHost "*:443">
  ServerName xxxx
  Use ssl
  RewriteEngine On
  RewriteRule (.*/wms|/openlayers3/.*) http://localhost:8080$1 [P,L]
  RewriteRule .* [F]
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我尝试过但没有成功:

  • Timeout 400
  • ProxyTimeout 400
  • 代理集
<Proxy "http://localhost:8080/">
  ProxySet connectiontimeout=100 timeout=400
</Proxy>
Run Code Online (Sandbox Code Playgroud)
  • ProxyPass "/" "http://localhost:8080" connectiontimeout=100 timeout=400

无论我使用上述哪个指令,超时始终为 1 分钟。

xim*_*ica 5

该超时只能在全局范围内进行控制。将全局Timeout设置更改httpd.conf为您的首选值:

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 400
Run Code Online (Sandbox Code Playgroud)

也许更好的方法是使用 nginx:

server {
    listen       443;
    server_name  xxxx;
    # ... ssl setup ...

    location ~* /wms$ {
        proxy_pass http://localhost:8080;
        proxy_read_timeout 400;
    }

    location /openlayers3/ {
        proxy_pass http://localhost:8080;
        proxy_read_timeout 400;
    }

    location / {
        return 403;
    }
}
Run Code Online (Sandbox Code Playgroud)

nginx 文档的附加链接,以便您了解此代码片段中发生的情况:

对于我的代码片段中缺少的 SSL 配置,另请阅读文档

  • @david.perez 但我真的建议只使用 Nginx。它更强大、更可靠、速度更快,而且您可以按照您想要的方式轻松配置它。 (2认同)
  • 现在我有时间测试nginx,它比apache运行得更好,而且语法看起来更简单,谢谢。 (2认同)