nginx - 如何在匹配后仅 proxy_pass 剩余的 URL

标签 nginx nginx-location

仅当匹配到位置时才需要代理传递剩余的 url

location /blog { proxy_pass http://example.com }

即,如果有人请求/blog/page1/temp.html,他们就会将代理传递给example.com/blog/page1/temp.html

我想将其更改为 example.com/page1/temp.html

最佳答案

I want to change example.com/blog/page1/temp.html to example.com/page1/temp.html

在代理传递指令中指定 uri(在本例中主机名后面的 /):

location /blog/ {
    proxy_pass http://example.com/;
}

或者像这样使用重写:

location /blog {
    rewrite /blog/([^/]+) $1;
    proxy_pass http://example.com
}

关于nginx - 如何在匹配后仅 proxy_pass 剩余的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48922208/

相关文章:

nginx - 在 nginx 配置中,如何直接在配置文件中显示一些内容到日志文件?

php - 502 错误网关 nginx/1.19.1

docker - nginx docker proxy_path到服务器中另一个docker的路径

正则表达式查找匹配文件扩展名的文件,除非文件名包含字符串

php - fatal error : Class 'ZMQContext' not found ( but it is installed and works on the terminal )

nginx - 带有身份验证网址的Google Kubernetes引擎(GKE)入口

nginx - 在网站子目录中设置 phpMyAdmin

php - 多个远程上传服务器到服务器

Nginx try_files 不适用于默认 index.html

node.js - nginx 上的代理传递 Socket.IO 连接不起作用