# 502 Bad Gateway after trying to setup www redirect to domain without www

**URL:** <https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669>\
**Category:** Developer help\
**Created:** [August 23, 2023, 12:31am UTC](https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669 "2023-08-23T00:31:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![melaniecarr23](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/melaniecarr23/32/25996_2.png) [@melaniecarr23](https://forum.ghost.org/u/melaniecarr23)\
**Post date:** [August 23, 2023, 12:31am UTC](https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669/1 "2023-08-23T00:31:40Z")

</div>

If you’re looking for help, please provide information about your environment. If you delete this template and don’t provide any information, your topic will be automatically closed.

If you aren’t running the latest version of Ghost, the first thing we’ll ask you to do is update to the latest version of Ghost.

- **What’s your URL**? Listed in the nginx files below

- \*\*What version of Ghost are you using?\*\*1.24.2  
And

- How was Ghost installed and configured? digital ocean ghost droplet configured to setup secondary domain and ssl, then configured for primary

- What Node version, database, OS & browser are you using? node 16.20.1, mysql, ubuntu 22, safari

- What errors or information do you see in the console? I don’t. ghost doctor did not return errors.

my files: /etc/nginx/sites-available/justmillit.com.conf

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

    server_name justmillit.com;
    root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)

    ssl_certificate /etc/letsencrypt/justmillit.com_ecc/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/justmillit.com_ecc/justmillit.com.key;
    include /etc/nginx/snippets/ssl-params.conf;

    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;
        proxy_pass http://127.0.0.1:2369;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

```

/etc/nginx/sites-available/www.justmillit.com.conf

```auto
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name www.justmillit.com;
    return 301 https://justmillit.com$request_uri;

    ssl_certificate /etc/letsencrypt/www.justmillit.com/fullchain.cer;
    ssl_certificate_key /etc/letsencrypt/www.justmillit.com/www.justmillit.com.key;
    include /etc/nginx/snippets/ssl-params.conf;

    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;
        proxy_pass http://127.0.0.1:2369;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 1g;
}

```

- What steps could someone else take to reproduce the issue you’re having? I’m not sure! The site was working before I attempted to get the secondary domain setup, and I don’t know why my change isn’t working right. I changed the files so [www.justmillit.com](http://www.justmillit.com) should redirect to [justmillit.com](http://justmillit.com), and added links to each domain’s SSL files from let’s encrypt.

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [August 23, 2023, 8:07am UTC](https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669/2 "2023-08-23T08:07:56Z")

</div>

Welcome to the Ghost community, @melaniecarr23.

A couple of observations.

1. Ghost will only work with one URL, i.e., WWW or non-WWW. It looks like the installer created the first config, but not the second. Did you create this file?

2. The gateway error implies that the non-WWW site is not set up in Nginx. Did you create a symbolic link to `sites-enabled`? Nonetheless, don’t do this until you have a working site.

3. Non-HTTP isn’t redirecting to HTTPS.

Please confirm your preferred URL, and `"url":` from `config.json.production`, and your choice when installing Ghost.

Finally, did you use the 1-click installer? This indicated that SSL isn’t correctly configured.

---

<div class="post-metadata">

**Author:** ![melaniecarr23](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/melaniecarr23/32/25996_2.png) [@melaniecarr23](https://forum.ghost.org/u/melaniecarr23)\
**Post date:** [August 23, 2023, 9:47pm UTC](https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669/3 "2023-08-23T21:47:18Z")

</div>

I did the 1 click installation, and originally setup www. Problem is, most folks will enter the domain without www, so I was trying to setup SSL for both and have one redirect to the other.

from the json file: “url”: “[https://justmillit.com](https://justmillit.com)”

Yes, I setup the symlink for both www and non-www in nginx.

I don’t get it.

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [August 24, 2023, 8:41am UTC](https://forum.ghost.org/t/502-bad-gateway-after-trying-to-setup-www-redirect-to-domain-without-www/40669/4 "2023-08-24T08:41:26Z")

</div>

Currently, neither WWW nor non-WWW appear to work. I suggest you revert your changes, so the site works, and then go through the necessary changes.

Please note:

- Ghost can only have one domain pointed at it, which is defined in config.production.json, and the SSL certificate is created for this.
- You can add server blocks to the top of the working Nginx config to redirect non-HTTPS to HTTPS, and WWW to non-WWW, e.g.:

```auto
server {
    listen 80;
    listen 443 ssl;
    server_name www.justmillit.com;
    return 301 $scheme:justmillit.com$request_uri;
}

```

Change the Ghost config:

```auto
# Change your config
ghost config url https://my-canonical-domain.com
# Generate an SSL setup for the domain
ghost setup nginx ssl

# Verify your Nginx config
sudo nginx -t
# Reload nginx with the new config
sudo nginx -s reload

```
