Ghost | Docker | Nginx Reverse Proxy | Lets Encrypt

Hello, I’m currently in the process of spinning up a self hosted instance of ghost using the latest image from here and docker in swarm mode (ghost is running as a single node for now). For reference I’ve attempted equivelent configurations in swarm, docker-compose up, and docker run ...

Base information:
Ghost version details (from the admin panel):

Version: 3.40.5
Environment: production
Database: sqlite3
Mail: Direct

Environment:

OS: Ubuntu 20.04.1 LTS x86_64
Docker version: Docker version 19.03.8, build afacb8b7f0
Docker-Compose version: docker-compose version 1.27.0-rc1, build f9228ae4

compose.yml:

version: ‘3.1’

services:

ghost:
image: ghost
restart: always
ports:
- 3001:2368
environment:
- url=http://ghost:3001
- NODE_ENV=production
volumes:
- ${GHOST_DIR}/data:/var/lib/ghost/content:rw

URL: https://eleweb.elesoft.dev

Nginx configuration:
Nginx is running on a separate instance hence the proxy_pass forwarding to the host:ports where the docker container is running:
(removed lets encrypt paths etc)

server {
server_name eleweb.elesoft.dev;

    location / {
            proxy_pass http://192.168.1.127:3001/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
    }

}
server {
if ($host = eleweb.elesoft.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot

    server_name eleweb.elesoft.dev;
listen 80;
return 404; # managed by Certbot

}

The problem:
The site mostly works, i can access the page and login to the admin panel, but i sometimes see instances of whatever url= is set to in compose.yml, i’ve tried the following variations of that variable:

url=https://eleweb.elesoft.dev

Results in a 301 when accessing the site

url=http://localhost:3001

Results in the site 90% working, but in the admin panel, preview site etc returns a 404 (it’s redirecting to localhost:3000), for example if i click the “E” logo on the main page

can someone explain what the url environment variable is exactly and how it should be set given my current environment configuration?

Thanks in advance
-Mark