0

A seemingly very simple reverse proxy config is giving me headache here. Main config file /etc/nginx/nginx.conf has "include /etc/nginx/conf.d/*.conf;"

Then I have two conf files under conf.d: default-1.conf and default-2.conf First file has:

server {
  # HealthCheck 
  server_name _;
  listen 0.0.0.0:443 ssl ;
  location = /health.html {
  root /usr/share/nginx/html;
 }
}

And second file has additional proxy statements as

server {

 listen 0.0.0.0:443 ssl ;

 server_name www.example2.com;    
 ...    
 location / {    
 set $backend "some-backend";    
 proxy_pass $scheme://$backend;     
 }  
}

When there is only default-1.conf is under conf.d/, curl -k https://localhost/health.html works.

If I also put default-2.conf under conf.d/, then same curl command gives 404 Not Found. I don't see any error under error.log either. What am I doing wrong?

How can I learn the rules applied during building final conf file using these multiple smaller conf files?

Thank you.

BBDG
  • 147
  • 1
  • 2
  • 7

1 Answers1

1

Your server_name _; doesn't make this a default catch-all server. From NGINX Server names:

In catch-all server examples the strange name _ can be seen:

server {
    listen       80  default_server;
    server_name  _;
    return       444;
}

There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name. Other invalid names like -- and !@# may equally be used.

And a bit further:

Note that there is no way to specify the catch-all name or the default server using the server_name directive. This is a property of the listen directive and not of the server_name directive.

Your default-1.conf should have:

server {
    # HealthCheck 
    listen       0.0.0.0:443  ssl  default_server;
    server_name  _;

    location = /health.html {
        root /usr/share/nginx/html;
    }
}
Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122