Redirecting Traffic from to

I’ve decided to use the one-click Ghost install on digitalocean, and I like how easy it has made the process. However, I am having an issue with my site. I want to redirect the to, but my config doesn’t seem to work.

I have Letsencrypt certs for my domain which is, and it works fine. It gives a cert error if you try, so since I don’t want people browsing to www, I’d rather just have it forwarded to I’ve setup www as a CNAME that points to the main domain.

My NGINX config is as follows (/etc/nginx/sites-available/

server {
    listen 80;
    listen [::]:80;

    root /var/www/ghost/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;


    location ~ /.well-known {
        allow all;

    client_max_body_size 50m;

I’ve tried modifying it so it looks like the following but it doesn’t redirect:

redirect 301$request_uri;

I haven’t modified

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Because you want to redirect a request from to you want to create a new server directive that is listening for connections on just and then add the redirect.

So you would need to update your configuration with the following:

server {
    return 301 $scheme://$request_uri;

In the snippet that you posted you had both server_names present, which may have been causing the issue.

You can find a more detailed write here: How to redirect with Nginx