0

I have two sites-enabled for nginx.

I have the default server:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
}

and I have a FQDN with a redirect for https:

server {
    listen SERVER-IP:80 ;
    listen [::]:80;
    server_name FQDN;

    location / {
       return 301 https://$host$request_uri;
    }
}

My issue is that if I try to access my server using a different domain name or using the IP address, using http on port 80, I will always be redirected to https on port 443. I cannot seem to get the default server to respond at all.

I even created another server block that begins:

server {
    listen 80;
    listen [::]:80;

    server_name OTHER-FQDN;

And even when I try to load http://OTHER-FQDN I get redirected to https port 443 with a certificate of FQDN.

Why?

Or better: how can I gain insight into which server block is being used for which request? Clearly only the block with FQDN is ever accessed even though I have another OTHER-FQDN that matches or a default_server that should match.

I am frustrated because the inner working of nginx in this case seem so opaque to me and counter to exectation.

Aron
  • 1
  • You could try using `listen 80;` instead of `listen SERVER-IP:80;` so that all the `server` blocks use the same `listen` value. – Richard Smith Aug 28 '21 at 16:38
  • I tried. It makes no difference. (The reason I added the IP is that my server has 2 IPs and I wanted something else to respond to requests coming in on the other one.) – Aron Aug 28 '21 at 16:44

0 Answers0