Nginx : thousands of server_name

nginx

how can I configure Nginx restrict to thousands of different server_name without creating thousands of external config files or writing a very long server_name line ?

Indeed, I would like Nginx be a reverse-proxy only for server1.com, server2.com, etc…

The best solution for me would be to have a single external config file containing my restricted server_names : server1.com, server2.com, etc…

Is it possible ?


Ok, thank you for your answers, it works without reg. expressions. Just a big server_name list as explained by kolbijack.
Thx.

Best Answer

You can put the server_name directive in a file all by itself and then just include it from your server block:

# example.com.conf
server {
  include /path/to/server_names;
  ...
}

# /path/to/server_names
server_name
  example.com
  domain.com
  foo.com
;

The server_names file just needs server_name at the top and ; at the bottom to be a valid directive.