0

I created a shiny app in R that I'm hosting on a server at the 3838 port. I'm totally new to this, so I just followed tutorials. However, this problem has stumped even our brilliant IT guy.

My SSL is set up using lets encrypt and certbot for my website: www.example.com. However, if someone types in example.com, it doesn't redirect to the SSL, and instead takes me to a not secure privacy warning page. How can I get the non-www to redirect to the www? I'm running ubuntu 18.04.

    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


   listen 80 default_server;
   listen [::]:80 default_server ipv6only=on;
   server_name example.com www.example.com;
   return 301 https://$server_name$request_uri;


}

server {
   listen 443 ssl;
   server_name example.com www.example.com;
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # m$
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; #$
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_prefer_server_ciphers on;
   ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

   location / {
       proxy_pass http://[IP Address]:3838;
       proxy_redirect http://[IP Address]:3838/ https://$host/;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection $connection_upgrade;
       proxy_read_timeout 20d;
   }```

I'm hosting on google domain and it is pointing at both www and the plain @.
missgwolf
  • 101
  • You have two problems. 1) To redirect from `https://example.com` to `https://www.example.com` you need a certificate that covers both domain names. 2) Your current configuration does not redirect from `https://example.com` to `https://www.example.com`. See [my answer on SO](https://stackoverflow.com/questions/42228191/nginx-redirect-non-www-to-www-https/42230968#42230968). – Richard Smith May 30 '20 at 07:50
  • I tried this but it didn't work. All I needed was the certificate for both domains. I posted the solution but @Ward-Reinstate Monica deleted it - I have no idea why. The solution is `sudo certbot --nginx -d www.example.com -d example.com`. It puts both domains on the same certificate and negates the need for a redirect. – missgwolf May 31 '20 at 08:04
  • Change "return 301 https://$server_name$request_uri;" to "return 301 https://www.example.com$request_uri; – Admiral Noisy Bottom Jun 04 '20 at 10:32

0 Answers0