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

Reinis Rozitis r at
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 it works perfectly fine whereas when I hit 
> (port 80) does not get redirected to (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;
      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.


More information about the nginx mailing list