Trouble with Ghost in Docker + nginx reverse proxy

Hey :)
I have some trouble setting up my Ghost instance.
When I try to call Ghost via the URL (ghost.schlosser.pw), I only get a “502 Bad Gateway” error message. Therefore I assume that there is a configuration error in the nginx config file on my side.
Could anyone take a look at my config file and help me out? I looked virtually everywhere to find a solution for this, but it seems like solutions that worked for others do not work for me :(

I am running Ghost in a Docker container, and I use nginx locally on my Ubuntu server to act as a reverse proxy plus SSL in combination with Lets Encrypt.

Ghost version: 5.13.2
nginx config:

 server {
          listen        80;
          server_name   ghost.schlosser.pw;

          location / {
            proxy_pass http://127.0.0.1:8081; # The port I assigned the container
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          # 2 lines below are to avoid Ghost https redirect bug
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_buffering off;
}

Ghost environment variables:
url: “http://ghost.schlosser.pw

What is it I am missing here?

Thanks in advance for any help!

Why do you use docker? :thinking:

Because I prefer to use Docker for many things rather than installing everything directly on the machine

I run ghost in docker as well. But I. Using caddy instead of nginx.

Have a look at my guide, using this setup right now:

Thank you, I’ll take a look at your guide :)

While your guide is certainly well-written, I couldn’t use it for my setup.
This is what I did today, and my site works now:

  • Update the Docker image to the latest version (currently 5.14.2)
  • Accessed the page from the machine hosting it and created my account

Then, just for fun, I decided to access the URL on my PC - and now it works.
I don’t know what it was that caused the error, but it seems to be working - for now at least :D

Thanks anyway!

Very strange that this configuration doesn’t work using Ghost’s own documentation on this subject.

Here is the nginx configuration I have had to use when reverse proxying to a ghost docker container. I have stripped out most non-essential nginx directives, so this should work as the bare minimum configuration. I still do not understand why I had to create locations for assets, public, and ghost. It doesn’t work correctly without them.

/etc/nginx/sites-available/ghost.conf

upstream ghost_backend {
    server 10.10.10.10:2368; # replace ip addr and port number with the host ip and port hosting the ghost docker container
}

# redirect port 80 > 443
server {
    listen 80;
    listen [::]:80;
    server_name domain.com;
 
    include /etc/nginx/h5bp/basic.conf;
    include /etc/nginx/moz_nossl;
 
    access_log /var/log/nginx/domain.com_80.access.log upstreamlog;
    error_log /var/log/nginx/domain.com_80.error.log warn;
 
    return 301 https://domain.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain.com;
    
    set $ghost_server "http://ghost_backend";
 
    include /etc/nginx/h5bp/basic.conf;
    include /etc/nginx/moz_ssl;
 
    access_log /var/log/nginx/domain.com.access.log upstreamlog;
    error_log /var/log/nginx/domain.com.error.log warn;
 
    location / {
        include proxy_params;
        proxy_pass $ghost_server;
    }
 
    location ^~ /assets/ {
        include proxy_params;
        proxy_pass $ghost_server;
    }
    
    location ^~ /public/ {
        include proxy_params;
        proxy_pass $ghost_server;
    }
 
    location ^~ /ghost/ {
        include proxy_params;
        proxy_pass $ghost_server;
   }
 
}

/etc/nginx/proxy_params:

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Host $host;
 
client_max_body_size 0;
client_body_buffer_size 1m;
proxy_intercept_errors on;
proxy_buffer_size 4k;
proxy_buffers 64 4k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 256k;
proxy_max_temp_file_size 0;
proxy_read_timeout 300;

This coide is also available on my pastebin at:
https://paste.travisflix.com/?e7c98869eda78e03#4BisSfjzBRsDvpNCE3HSmBqNgEaTLHZKAHeGeMUJ18Fv