By mdn
Hi all,
I’ve set up an Ubuntu 16.04 VPS with a Jekyll site and LetsEncrypt using tutorials found on this site.
I’d like to get https://www.example.com redirecting to https://example.com however I’m having difficulty getting nginx to co-operate. Where am I messing up?
My current server block (directly after the one that was autocreated using certbot in sites-enabled) looks like:
server {
listen 80;
server_name example.com.au;
return 301 https://example.com.au$request_uri;
}
server {
listen 80;
server_name www.example.com.au;
return 301 https://example.com.au$request_uri;
}
I’ve tried modifying this to listen on port 443. I’ve tried adding these to sites-available. I’ve restarted. But none of my modifications actually make any changes. They dont’t even break the site which would at least tell me if anything I’m doing is having ANY effect.
curl -l www.example.com shows a 401 redirect, to https I presume.
curl-l https://www and non www both bring back the site.
Where am I going wrong?
EDIT: A little further digging
So I ran sudo nginx -t and it returns OK. But then I ran service nginx config test and I got a fail. I then ran sudo nginx -c /etc/nginx/sites-enabled/default -t and got:
nginx: [emerg] “server” directive is not allowed here in /etc/nginx/sites-enabled/deafult:16
But that one is one that was created by certbot? Not sure what’s going on there.
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!
So I think it has something to do with the sites-available file not being included properly in the nginx.conf? But I’m not sure. I’m lost!
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.