I have the following nginx config:
location /mail {
rewrite ^/mail/(.*) /$1 break;
proxy_pass https://roundcube-host;
References to nginx docs: HttpCoreModule#location, HttpProxyModule#proxy_pass.
There is a better way than using regex (which is slow) for location match. In this case, you could use ^~
to tell nginx to match the given prefix /mail
before doing any regex match. You also don't need that rewrite rule because proxy_pass
can do that simple rewrite by itself (by adding a trailing slash /
in the upstream server url).
My suggestion is to replace
location ~ ^/mail(.*)$ {
rewrite ^/mail/(.*) /$1 break;
proxy_pass https://roundcube-host;
by
location ^~ /mail {
proxy_pass https://roundcube-host/;