a duplicate default server for 0.0.0.0:80 in /etc/nginx/nginx.conf:39

Reinis Rozitis r at roze.lv
Thu Nov 26 08:46:34 UTC 2020


> Is there a way to enable redirect from port 80 to 443 for both /etc/nginx/conf.d/onetest.conf and /etc/nginx/nginx.conf files.  Any help will be highly appreciated.

You can have only one default_server per listen port.
It will be the used if a client makes a request not matching any hostnames in server_name definitions (for example request to servers IP without giving a hostname).

If there is no 'default_server' nginx will pick the first one by the order in configuration.

So in general you don't need to specify the default_server at all (unless it's somewhere in the middle of configuration).

In your case:

>cat /etc/nginx/conf.d/onetest.conf
>server {
>     listen       80 default_server;
>      server_name  onetest.mydomain.io;
>      return       301 https://$server_name$request_uri;
>}

You should remove default_server here (or in the nginx.conf).


In case you just want to force all your virtualhosts to https might as well just use a general redirect for all of them (have a single server {} block for all the redirects):

Server {
      listen       80 default_server;
      server_name _;
      return       301 https://$host$request_uri;
}


rr



More information about the nginx mailing list