【问题标题】:Nginx proxy_pass with rewrite in url?Nginx proxy_pass 在 url 中重写?
【发布时间】:2023-03-08 17:54:02
【问题描述】:

我想实现一个反向代理,将http://www.dummy.com/foo/bar/test 的请求重定向到http://127.0.0.1/hello/world。我试图在通过之前添加重写,它似乎不起作用......

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 没有被重写。我稍后会发布日志。谢谢

标签: nginx url-rewriting reverse-proxy


【解决方案1】:

上述配置按预期工作...当我测试上述配置时,另一台服务器配置错误。

【讨论】:

    猜你喜欢
    • 2017-05-12
    • 2017-11-13
    • 1970-01-01
    • 2018-10-19
    • 2018-02-16
    • 2023-03-22
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多