gpt4 book ai didi

nginx proxy_pass 正在设置端口作为响应

转载 作者:行者123 更新时间:2023-12-05 01:46:59 25 4
gpt4 key购买 nike

我的 Nginx 配置类似于:

server {
listen 80;
listen 443;
server_name api.mysite.dev;

location / {

proxy_set_header Host "api.mysite.dev";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $scheme://127.0.0.1:8001;
}

}

server {
listen 80;
listen 443;
server_name mysite.dev www.mysite.dev;

# Forward all /api/ requests ti api.mysite.dev
# sadly need to keep this around for backwards compatibility
location /api/ {
proxy_set_header Host "api.mysite.dev";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $scheme://127.0.0.1:8001/;

}
# The proxy_pass here ends up putting the port (8002) in the response URL.
location / {
proxy_set_header Host "www.mysite.dev";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $scheme://127.0.0.1:8002;
}
}

所以,正如评论中所说,当我请求 www.mysite.dev 时,我的浏览器被转发到 www.mysite.dev:8002。知道我在这里做错了什么吗?

提前致谢!

最佳答案

您必须设置以下选项:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;

这是一个有效的示例:

    server {
listen 80;
listen 443;
server_name api.mysite.dev;

location /api/ {
proxy_pass http://127.0.0.1:8001/;
proxy_redirect off;

proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host "api.mysite.dev";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}

关于nginx proxy_pass 正在设置端口作为响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33003069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com