Nginx:poxy_pass 不同位置到不同端口

Nginx: poxy_pass different locations to different ports

所以基本上,我想 poxy_pass 根位置,即 www.domain.com/ to one port and all other routes i.e. www.domain.com/* 到不同的端口。我现在所做的是:

server {
        listen 80;
        listen [::]:80;

        server_name www.domain.com;
        location /pricing {
                proxy_pass http://localhost:4025;
        }

        location / {
                proxy_pass http://localhost:4033;
        }
}

它有效,但我确实有其他路线,如 定价 和子路线,如果我导航到这些路线,它不会按预期工作。那么有没有像这样的全局解决方案:

location @other {
                    proxy_pass http://localhost:4025;
}

更新:

我已经这样做了,它解决了我的问题,但是可行吗?

server {
    listen 80;
    listen [::]:80;
    
    server_name www.domain.com;

    location ~ [/](assets)(.*) {
                proxy_pass http://localhost:4025;
        }

    location ~ [/]((stylesheets)|(javascripts)|(images)|(fonts))(.*) {
                proxy_pass http://localhost:4033;
        }
    
    location ~ [^\/](.*) {
        proxy_pass http://localhost:4025;
    }

    location / {
                proxy_pass http://localhost:4033;        
    }
}

最简单快捷的解决方案:

server {
    listen 80;
    listen [::]:80;
    
    server_name www.domain.com;
    
    location ~ [^\/](.*) {
        proxy_pass http://localhost:4025;
    }

    location / {
                proxy_pass http://localhost:4033;        
    }
}