【问题标题】:nginx reverse proxy unexpected redirectnginx反向代理意外重定向
【发布时间】:2021-01-12 19:02:55
【问题描述】:

我有 nginx 作为反向代理运行,配置为 /etc/nginx/sites-enabled/10.0.0.1.conf

server {
    listen 80;

    server_name 10.0.0.1;

    location /blog/ {
        proxy_pass http://127.0.0.1:8080/;
    }
}

以及在 127.0.0.1:8080 上运行的博客服务。

当我在机器上查询 http://localhost/blog/ 时,我从博客服务中得到了预期的响应。但是,当从http://10.0.0.1/blog/ 查询时,nginx 会重定向到http://10.0.0.1,仅此而已。

这个配置有什么问题?为什么http://10.0.0.1/blog/ 不反向代理到 http://localhost:8080 博客服务?

nginx 版本:nginx/1.18.0 (Ubuntu)

【问题讨论】:

  • 您确定重定向是由于 Nginx 而不是 proxy_pass 目标而发生的吗?我不确定您的 proxy_path (URI) 中是否需要斜杠。 Check the doc
  • 我关闭了博客应用程序,因此 8080 上没有任何内容,并且重定向仍然发生。
  • curl -I http://10.0.0.1/blog/ 返回什么?

标签: http nginx networking nginx-reverse-proxy


【解决方案1】:

这是 chrome 缓存来自 nginx 对 http://10.0.0.1/blog/ 的旧响应。清除浏览器缓存并再次尝试得到了预期的结果。

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2021-04-06
    • 2020-05-31
    • 1970-01-01
    相关资源
    最近更新 更多