Nginx版本1.14.0
nginx.conf文件(下面的“假”域已正式注册):
http {
#default stuff...
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name mydomain.registered.com;
location / {
proxy_pass http://127.0.0.1:8001/;
#I also tried with the server's actual IP
#I also tried with or without the slash at the end
}
}
#default stuff...
}假设服务器的“假”IP是10.70.0.65,我的API是:
http://10.70.0.65:8001/auth/login
http://10.70.0.65:8001/auth/logout
etc...我的上述API服务器是一个正在运行的带有端口映射的码头容器,如下所示:
0.0.0.0:8000-8001->8000-8001/tcp, :::8000-8001->8000-8001/tcp当直接使用服务器的IP (例如http://10.70.0.65:8001/auth/login )调用API时,它可以工作。但是使用域名(如http://mydomain.registered.com/auth/login )进行调用不起作用。
我怎样才能让它起作用?
发布于 2022-04-13 08:49:52
尝试将Host:头传递给后端:
location / {
proxy_pass http://127.0.0.1:8001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}https://stackoverflow.com/questions/71854419
复制相似问题