Nginx - 将非根位置分配给 proxy_pass

Nginx - 将非根位置分配给 proxy_pass

我喜欢做的是代理来自的http://example.com/proxy/foo请求http://localhost:8060/foo

此配置代理http://example.com/proxy/foohttp://localhost:8060/proxy/foo

server {
    server_name example.com;


    location /proxy/ {
        proxy_pass http://localhost:8060;
    }

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

}

答案1

server {
    server_name example.com;


    location ^~ /proxy/ {
        rewrite ^/proxy(/.*)$ $1 break;    
        proxy_pass http://localhost:8060;
    }

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

}

相关内容