【发布时间】:2019-09-18 22:41:40
【问题描述】:
我尝试了以下 SO 答案,但没有成功 This one、this one 和其他一些。我也查看了文档,但是我无法弄清楚我做错了什么。当我点击 / 时,我得到了 nginx 主页(很好)。当我尝试点击 /alpha 时,我得到 404。冰壶到 127.0.0.1:5001 给了我我对主机的期望。谁能告诉我我错过了什么?
配置:
http {
server {
listen 80;
location /prealpha/ {
proxy_pass http://127.0.0.1:5000/;
}
location /alpha/ {
proxy_pass http://127.0.0.1:5001/;
}
location /beta/ {
proxy_pass http://127.0.0.1:5002/;
}
location /gamma/ {
proxy_pass http://127.0.0.1:5003/;
}
}
更新 来自 nginx 调试输出的以下日志似乎表明 keepalive 无法正常工作,然后连接被关闭。我是否需要使用上游或其他东西来使连接保持打开状态?
2019/09/18 12:11:03 [debug] 8688#8688: *2 http upstream request: "/alpha/?"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http upstream process header
2019/09/18 12:11:03 [debug] 8688#8688: *2 malloc: 000055B88E563AE0:4096
2019/09/18 12:11:03 [debug] 8688#8688: *2 recv: eof:0, avail:1
2019/09/18 12:11:03 [debug] 8688#8688: *2 recv: fd:9 484 of 4096
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy status 404 "404 NOT FOUND"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Server: gunicorn/19.7.1"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Date: Wed, 18 Sep 2019 12:11:03 GMT"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Connection: close"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Content-Type: text/html"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Content-Length: 232"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Set-Cookie: oidc_id_token=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly; Path=/"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header: "Vary: Cookie"
2019/09/18 12:11:03 [debug] 8688#8688: *2 http proxy header done
2019/09/18 12:11:03 [debug] 8688#8688: *2 xslt filter header
2019/09/18 12:11:03 [debug] 8688#8688: *2 posix_memalign: 000055B88E538C60:4096 @16
2019/09/18 12:11:03 [debug] 8688#8688: *2 HTTP/1.1 404 NOT FOUND
Server: nginx/1.14.0 (Ubuntu)
Date: Wed, 18 Sep 2019 12:11:03 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: oidc_id_token=; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly; Path=/
Vary: Cookie
Content-Encoding: gzip
重大更新
事实证明,nginx 正在将位置选择器(不确定 htis 实际称为什么,但在顶部的配置中它是显示“/prealpha/”的位)传递给 proxy_pass URL。我需要它不要那样做。它需要简单地将该点之后的所有内容传递给代理。我如何让它做到这一点?
【问题讨论】:
-
您在没有斜杠的情况下点击位置,但您的
location只能使用斜杠。当你点击/alpha/(希望尾部斜杠)时,结果是什么。 -
我刚收到 404。
-
访问日志显示它是 404 但没有错误日志。
标签: nginx