将子文件夹重写为子域而不用nginx重定向

问题描述:

我想请求http://example.com/products/some-variable重写为http://catalog.example.com/some-variable而不重定向用户。换句话说,URL不应该改变。将子文件夹重写为子域而不用nginx重定向

我发现了一个类似的例子here,但我似乎无法弄清楚如何做相反的事情。

在此先感谢!

我想在你的情况下,它会是这样的:

server { 

    listen 80; 
    server_name example.com; 

    location ~ ^/products/(.*)$ { 
    proxy_pass http://catalog.example.com/$1; 
    } 

} 

下面是文章与proxy_pass例子:

http://www.liaohuqiu.net/posts/nginx-proxy-pass/