所有主机重定向到单个Nginx proxy_pass [英] All hosts redirecting to single nginx proxy_pass
问题描述
.conf文件中包含以下内容:
I have the following in my .conf file:
server {
listen 80;
server_name mydomain.net;
access_log /var/log/nginx/mydomain.net.access.log main;
location / {
proxy_pass http://127.0.0.1:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
}
}
这可以正常工作...除了击中服务器的所有内容都被馈送到该服务器块.我的IP,指向此块的另一个域以及实际的mydomain.net都指向mydomain.net所指向的 only .
Which works just fine... except everything that hits the server is getting fed to this server block. My IP, another domain pointing at this block, and the actual mydomain.net all point to what only mydomain.net is pointing to.
推荐答案
作为文档状态:
在此配置中,nginx仅测试请求的标头字段主机",以确定应将请求路由到哪个服务器. 如果其值与任何服务器名称都不匹配,或者请求根本不包含此标头字段,则nginx会将请求路由到该端口的默认服务器.在上面的配置中,默认服务器是第一个服务器-这是nginx的标准默认行为.
In this configuration nginx tests only the request’s header field "Host" to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port. In the configuration above, the default server is the first one — which is nginx’s standard default behaviour.
这里就是这种情况.我执行了建议的步骤以删除未定义的主机:
This was the case here. I performed the suggested step to drop undefined hosts:
server {
listen 80 default_server;
server_name "";
return 444;
}
哪个解决了我的问题.
这篇关于所有主机重定向到单个Nginx proxy_pass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!