Report this

What is the reason for this report?

Cannot configure HTTPS for www subdomain using nginx server blocks

Posted on September 27, 2017

I want to stop this from happening https://www.site.com/articles/abc This should be redirected (to remove www) as in my server block configuration. I don’t understand why however. I have looked a lot at similar solutions on server fault and wonder if there is something more specific for DO.

here is the config thank you for help.

server {
    listen 80;
    listen [::]:80;
    server_name site.com www.site.com;
    return 301 https://$server_name$request_uri;
}

server {
        listen 443 ssl;
        listen [::]:443 ssl http2;
        include snippets/ssl-site.com.conf;
        include snippets/ssl-params.conf;

        root /var/www/site.com/html;

        index index.html index.htm index.nginx-debian.html index.php;

        server_name site.com www.site.com;
        #rewrite ^ https://site.com$request_uri? permanent;
        #return 301 https://$server_name$request_uri;

        add_header X-Frame-Options "SAMEORIGIN";

        rewrite ^(.*)/(\d+)-([^/]+)(.*)$ $1/$3 permanent;
        rewrite ^.*\.(pptx)$ https://caribbean-diving.com permanent;

        location ~* \.(?:css|js|gif|jpeg|jpg|png)$ {
                expires max;
                add_header Cache-Control public;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

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

}

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.