重写url中的Nginx proxy_pass?
问题描述:
我想实现一个反向代理,将http://www.dummy.com/foo/bar/test的请求重定向到http://127.0.0.1/hello/world。我曾尝试通过之前添加重写,似乎不工作...重写url中的Nginx proxy_pass?
server {
listen 80;
listen [::]:80;
server_name www.dummy.com;
# access_log /var/log/nginx/upstream_log.log
location/{
root /usr/share/nginx/html/dummy;
}
location /foo/bar/test {
rewrite ^/foo/bar/test /hello/world break;
proxy_pass http://127.0.0.1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/upstream_log.log upstream_logging;
}
}
有什么遗漏或配置错误?
答
上述配置按预期工作......当我测试上述配置时,其他服务器配置错误。
什么不起作用?结果是什么?日志文件中是否有某些内容? –
当我向邮递员发送nginx请求时,它返回http状态404。似乎URL没有被重写。我会稍后发布日志。谢谢 – Rex