例如,如果列出了任何子目录,则保留该子目录。但如果仅列出了 URL,则将用户转发到 localhost:3333/publiclink
location /.(az)$ {
proxy_pass http://127.0.0.1:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_ssl_server_name on;
}
location / {
proxy_pass http://127.0.0.1:3333/publiclink;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_ssl_server_name on;
}
答案1
您希望在将单个 URI传递至上游之前/
对其进行内部重写,但其他所有内容都透明地传递至上游。/publiclink
location
您可以使用以下语句通过精确匹配在内部重写单个 URI rewrite...last
:
location = / {
rewrite ^ /publiclink last;
}
location / {
proxy_pass http://127.0.0.1:3333;
...
}
rewrite...break
或者,在主函数中使用location
:
location / {
rewrite ^/$ /publiclink break;
proxy_pass http://127.0.0.1:3333;
...
}
第一个选项更有效。