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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Kaushal Shriyan
Hi,

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;
        #server_name  _;
        server_name marketplace.mydomain.com;
        ssl_protocols TLSv1.2;
        ssl_certificate /etc/ssl/certs/marketplace.mydomain.com/fullchain1.pem; ssl_certificate_key /etc/ssl/certs/marketplace.mydomain.com/privkey1.pem;
        if ($scheme = http) { return 301 https://$server_name$request_uri; }
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/certs/marketplace.mydomain.com/dhparam.pem;
        client_max_body_size 100M;
        root         /var/www/drupal/marketplace-v2/mpV2/web;
        access_log  /var/log/nginx/access.log;
        error_log  /var/log/nginx/error.log;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location = /favicon.ico {
        log_not_found off;
        access_log off;
        }

I will appreciate it if someone can pitch in for help. Please let me know if you need any additional configurations and I look forward to hearing from you. Thanks in Advance.

Best Regards, 

Kaushal

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

Reinis Rozitis
> 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

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

Reinis Rozitis
>       return       301 return 301 https://$server_name$request_uri;

Obviously a typo just a single return 301.

rr


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

Kaushal Shriyan


On Mon, Jun 15, 2020 at 11:55 PM Reinis Rozitis <[hidden email]> wrote:
>       return       301 return 301 https://$server_name$request_uri;

Obviously a typo just a single return 301.

rr



Thanks Reinis for the email and much appreciated. It worked like a charm. 

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx