Search code examples
apacheproxytimeout

Proxy timeout with ReWriteRule


There is no way of controlling timeout when proxying by means of ReWriteRule (mod_rewrite) with Apache 2.4.

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

I've tried unsuccessfully:

  • Timeout 400
  • ProxyTimeout 400
  • ProxySet
<Proxy "http://localhost:8080/">
  ProxySet connectiontimeout=100 timeout=400
</Proxy>
  • ProxyPass "/" "http://localhost:8080" connectiontimeout=100 timeout=400

The timeout is always 1 minute, no matter which of the above directives I use.


Solution

  • This timeout can be controlled only globally. Change the global Timeout setting in httpd.conf to your preferred value:

    #
    # Timeout: The number of seconds before receives and sends time out.
    #
    Timeout 400
    

    Probably a better way to do this would be to use 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;
        }
    }
    

    Additional links to nginx documentation so that you understand what's going on in this snippet:

    For the SSL configuration missing in my snippet please also read the documentation.