【问题标题】:One out of three Nginx routes ignores upstream server三分之一的 Nginx 路由忽略上游服务器
【发布时间】:2019-12-11 01:05:35
【问题描述】:

我已经为一个 nginx 反向代理配置了三个位置:

    location / {
            root /var/www/html;
            index index.html;
    }


    location /login {
            proxy_pass http://127.0.0.1:9080;

            proxy_set_header        Host                    $host;
            proxy_set_header        X-Real-IP               $remote_addr;
    }


    location /app {
            rewrite ^/app/(.*)$ /$1 last;
            proxy_pass https://10.11.12.13/1020/;

            proxy_set_header        Host                    $host;
            proxy_set_header        X-Real-IP               $remote_addr;
    }

监听 9080 端口的服务器重定向到路由/app/{generated subpath}。 IP 10.11.12.13 上的服务器处理{generated subpath} 上的请求。因此,我使用相应的重写规则删除前缀路径 /app,然后将请求代理到该服务器的 /1020 端点。

由于某种原因,nginx 反向代理没有走10.11.12.13 上游服务器,而是尝试在本地查找路径:

8888#8888: *470 open() "/var/www/html/html/createCustomer" failed (2: No such file or directory), client: x.x.x.x, server: 10.10.10.10, request: "GET /app/html/createCustomer?tokenId=0xC00FF3 HTTP/1.1", host: "10.10.10.10"

【问题讨论】:

    标签: nginx url-rewriting reverse-proxy proxypass


    【解决方案1】:

    而不是last,我相信您正在寻找break。来自rewritedocumentation

    最后

    停止处理当前的 ngx_http_rewrite_module 指令集并开始搜索与更改的 URI 匹配的新位置;

    starts a search for a new location matching the changed URi 是您删除 /app/ 部分时发生的情况,该部分随后与 / 位置匹配。

    休息

    停止处理当前集合

    【讨论】:

    • 哦,是的,这很神奇。谢谢 !!!现在 nginx 使用那个服务器,还有一个小 bug:它不会使用写入 proxy_pass 指令的 /1020/ 端点.........
    • 你能把它标记为这个问题的答案吗?然后我会打开另一个问题,更详细地解释您的其他问题,因为它与您的其他问题一起丢失了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 2019-12-02
    • 2018-09-06
    • 1970-01-01
    相关资源
    最近更新 更多