Reputation: 2495
Consider two websites hosted on the same server: domain.com
and foo.domain.com
. I want to start up a monitoring panel for each site on port 5555. Each site has a separate monitoring panel so I need to use nginx to route domain.com:5555
and foo.domain.com:5555
to two different places.
Here is the configuration for foo.domain.com
:
server {
listen 5555;
server_name foo.domain.com;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:5678;
}
}
While this works fine for foo.domain.com:5555
, it is also routing domain.com:5555
to the monitoring panel. This is acting like I had defined server_name domain.com foo.domain.com
, but clearly I only defined it for foo.domain.com
.
The only other nginx configs on the server are for ports 80 and 443. Neither of those configs use any wildcards and explicitly use the full name.
Upvotes: 1
Views: 43
Reputation: 49742
nginx
always has a default server - if you do not define a default server, it will use the first server block with a matching listen
directive.
If you want to discourage this behaviour, you will need to define a catch-all server for port 5555.
For example:
server {
listen 5555 default_server;
return 444;
}
See this document for more.
Upvotes: 1