Nginx 在端口 80 上运行,我使用它来反向代理 URL,并/foo
以3200
这种方式使用端口路径:
location /foo {
proxy_pass http://localhost:3200;
proxy_redirect off;
proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我在 port 上有一个应用程序3200
,我不希望将初始/foo
值发送到该应用程序。也就是说 - 当我访问时http://localhost/foo/bar
,我只想/bar
成为应用程序接收到的路径。所以我尝试将此行添加到上面的位置块:
rewrite ^(.*)foo(.*)$ http://localhost:3200/$2 permanent;
Run Code Online (Sandbox Code Playgroud)
这会导致 302 重定向(更改 URL),但我想要 301。我该怎么办?