2

This is my config:

upstream beta {     
  server localhost:49213;
}
server {     
  listen 80;
  server_name beta.example.com;
  location / {
    proxy_pass http://beta;     
  }   
}
server {
  listen 80;
  server_name "";
  return 444;
}

When I open localhost:80 I also see the content of localhost:49213. I find it wrong. Nginx should reject all requests that don't have beta.example.com in Host HTTP header, right? Why it's not happening?

1 Answer 1

3

OK, here is the answer. The server with an empty server_name has to be declared as a "default" one. More details here: http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name

Nginx, when Host HTTP header doesn't match any servers, goes into the default one, which is the first, if not specified otherwise. Here is the config that works:

upstream beta {     
  server localhost:49213;
}
server {     
  listen 80;
  server_name beta.example.com;
  location / {
    proxy_pass http://beta;     
  }   
}
server {
  listen 80 default_server; # pay attention!
  server_name "";
  return 444;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .