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;
}
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
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;
}
}