【问题标题】:Nginx - Reverse proxy everything after location specificationNginx - 位置规范后的一切反向代理
【发布时间】:2021-09-12 07:37:29
【问题描述】:

我正在尝试使用 nginx 反向代理特定的位置规范,如下所示:

server {
    listen 80;
    server_name example.com;

    location /example {
        proxy_pass http://localhost:8080/test;
    }
}

现在,当我尝试访问 http://example.com/example/css/styles.css 的资源时,我希望它尝试访问 http://localhost:8080/test/css/styles.css。但可惜 - 我从 nginx 得到 404。

当我尝试访问 http://example.com/example 时,它会显示 http://localhost:8080/test 上的内容(所以我知道基本 url 段正在工作)减去从相对 url 导入该页面的任何内容(例如样式和 JS 文件)

如何让反向代理处理子 url 段?

【问题讨论】:

  • locationproxy_pass 参数末尾添加斜线。
  • @IvanShatsky 这似乎有效,谢谢!
  • 你可以找到更多关于proxy_pass与斜杠相关的行为herehere是我对proxy_pass的一些行为方面的详细解释。

标签: nginx reverse-proxy


【解决方案1】:

根据 Ivan 对原始问题的评论,这是一个添加了斜杠的工作配置:

server {
    listen 80;
    server_name example.com;

    location /example/ {
        proxy_pass http://localhost:8080/test/;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-14
    • 2020-12-18
    • 2019-03-14
    • 2017-06-20
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多