redirect from http (port 80) to https (port 443) not working.

Reinis Rozitis r at roze.lv
Mon Jun 15 18:20:39 UTC 2020


> I am running nginx version: nginx/1.16.1 on CentOS Linux release 7.8.2003 (Core). When I hit https://marketplace.mydomain.com it works perfectly fine whereas when I hit http://marketplace.mydomain.com 
> (port 80) does not get redirected to https://marketplace.mydomain.com (port 443). I have the below nginx.conf.
>
> server {
>        listen 443 ssl default_server;
>       #listen       80 default_server;


Either reenable listen       80 default_server; or add another server block:

server {
      listen       80 default_server;
      server_name marketplace.mydomain.com;
      return       301 return 301 https://$server_name$request_uri;
}

Because if you don't listen on port 80 the only way $scheme will be 'http'  (and the if condition true) if the client opens http://yoursite:443 which won't normally happen.

rr



More information about the nginx mailing list