0

I'm setting up a server to host a website at 'https://domain.tld'. I need http and https schemes of 'www.domaintld.com', 'domaintld.com', and 'www.domain.tld' to all redirect to 'https://domain.tld'. I thought I had it all nice and happy, and with Chrome on Mac it's happy as a clam. Unfortunately, it doesn't seem to work in any other browsers. I've had a hard time finding the appropriate settings, and I'm new to Nginx.

Current config:

...
server {
    listen 80;
    listen 443 ssl;
    server_name www.domaintld.com;
    return 301 $scheme://domain.tld$request_uri;
}

server {
    listen 80;
    listen 443 ssl;
    server_name domaintld.com;
    return 301 $scheme://domain.tld$request_uri;
}

server {
    listen 80;
    listen 443 ssl;
    server_name www.domain.tld;
    return 301 $scheme://domain.tld$request_uri;
}

server {
    # SSL configuration
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/ssl-domain.tld.conf;
    include snippets/ssl-params.conf;

    ...        

    location ~ /.well-known {
            allow all;
    }

    root /var/www/html;

    server_name domain.tld;

    location / {
            # Redirect to index instead of 404
            try_files $uri $uri/ /index.php$is_args$args;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            # With php7.0-cgi alone:
            # fastcgi_pass 127.0.0.1:9000;
            # With php7.0-fpm:
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    location ~ /\.ht {
            deny all;
    }
}
spectre6000
  • 455
  • 4
  • 17
  • 1) You redirect `http` to `http` and 2) `http://domain.tld` is handled by the default server (which will be the first server block). – Richard Smith Dec 07 '16 at 19:32
  • To resolve 1) change `$scheme` to `https` in each of the first three `server` blocks, correct? Please elaborate on 2). – spectre6000 Dec 07 '16 at 19:47
  • Where is your `server` block with `server_name domain.tld;` and `listen 80;`? But it doesn't matter now - fixing either (1) or (2) will solve your problem. – Richard Smith Dec 07 '16 at 19:55

0 Answers0