I have Nginx, running on Ubuntu 16.04 with several virtual hosts set up. After adding a LetsEncrypt cert, using certbot, I can no longer access my site with www.example.com Going to example.com works perfectly with either protocol. If I go to www.example.com with either protocol, the server returns the default server block. Here is my server block in the Nginx configuration files:
server {
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /var/www/example/public;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name example.com www.example.com;
return 302 https://example.com$request_uri;
}
I want the server to respond to https://www.example.com OR http://www.example.com the same way it currently responds to https://example.com
Posting the answer to help others who may end up in the same sitch.
Be sure to check all virtual hosts files. In my case Certbot had written a server block for the www version of my site within the digitalocean virtual host file. I deleted that server block and the code above worked as expected.
You can test your configuration to find if you have the same problem by doing the following:
sudo nginx -t
I hope this helps