nginx proxy pass subpaths not redirected

后端 未结 3 611
迷失自我
迷失自我 2020-12-13 09:36

I have the following nginx config:

    location /mail {
           rewrite           ^/mail/(.*) /$1 break;
           proxy_pass https://roundcube-host;
            


        
3条回答
  •  無奈伤痛
    2020-12-13 10:17

    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/;
    

提交回复
热议问题