Non-www redirect to www is not working on my server. Here is the following nginx configuration that I’m using. When I try on mobile or on a desktop browser it doesn’t connect and says webpage is unavailable. In mobile gives an DNS look-up failed.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.ca;
return 301 https://www.example.ca$request_uri;
}
server {
server_name www.example.ca;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-www.example.ca.conf;
include snippets/ssl-params.conf;
.
.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Have you setup a DNS an A-record for non-www also known as @ ? And since you’re using HTTPS, then you might want to redirect non-www for HTTPS too. If your certificate allows the non-www of course. And then we want to redirect www to HTTPS as well.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name example.ca www.example.ca;
return 301 https://www.example.ca$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-www.example.ca.conf;
include snippets/ssl-params.conf;
server_name example.ca;
return 301 https://www.example.ca$request_uri;
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.