Ubuntu nginx http -> https; non-www -> www

Discussion in 'Installation/Configuration' started by emcee, May 3, 2018.

  1. emcee

    emcee New Member

    Hi, I have an Ubuntu server with ispconfig 3.1.11 and nginx. Somehow redirect doesn't work as expected. www.domain.tld redirects fine to https://www.domain.tld but domain.tld doesn't redirect. It just shows the default nginx page. In my opinion, it should redirect to https://www.domain.tld. I've tested this in 3 different browsers. I'd appreciate any ideas. This is what my vhosts file looks like:
    Code:
    server {
            listen *:80;
    
            listen *:443 ssl;
                    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_certificate /var/www/clients/client2/web27/ssl/domain.tld-le.crt
            ssl_certificate_key /var/www/clients/client2/web27/ssl/domain.tld-le.key
            
            server_name domain.tld www.domain.tld;
    
            root   /var/www/domain.tld/web/;
    
            if ($http_host = "domain.tld") {
                rewrite ^ $scheme://www.domain.tld$request_uri? permanent;
            }
            if ($scheme != "https") {
                rewrite ^ https://$http_host$request_uri? permanent;
            }
     
  2. emcee

    emcee New Member

    I found a solution here. I just unchecked the Rewrite HTTP to HTTPS checkbox and added the following to nginx directives:
    Code:
    if ($scheme != "https") {
              rewrite ^ https://www.domain.tld$request_uri? permanent;
            }
    I left SEO redirect as it was: domain.tld => www.domain.tld. It works now.
     

Share This Page