Running Ghost on docker with nginx infront

Think someone could find this helpful.

This blog is setup as a docker container with an nginx in-front. I will write how I set it up and also what problem I got into when using https.

First of all it just setup ghost with the following command.

docker run --name twee-ghost -p 127.0.0.1:2368:2368 -v /var/www/ghost:/var/lib/ghost --restart=always -e "NODE_ENV=production" ghost

I did get into problems when running it as production enviorment so I needed to modify my config.js. This is how my production section looks now:

    production: {
        url: 'https://dev.twee-app.com',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(process.env.GHOST_CONTENT, '/data/ghost.db')
            },
            debug: false
        },

        server: {
            host: '0.0.0.0',
            port: '2368'
        },
           paths: {
            contentPath: path.join(process.env.GHOST_CONTENT, '/')
        }
    }

So the thing I have changed is url and also added

           paths: {
            contentPath: path.join(process.env.GHOST_CONTENT, '/')
        }

cause that was missing from the production section of the config and that caused ghost not to start.

When we got our docker container running. We will need to update our nginx config. So it will forward the request correctly.
Our configuration looks like this:

server {  
       listen         80;
       server_name dev.twee-app.com;

      location / {
       return         301 https://$server_name$request_uri;
      }
}

server {

    listen 443 ssl http2;
    server_name dev.twee-app.com;

    ssl_certificate /path/to/cert;
    ssl_certificate_key /path/to/cert;

    location / {
        proxy_pass http://localhost:2368;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto https;
        proxy_cache_bypass $http_upgrade;
    }
}

This configuration works fine, The problem I got into was that I got into an infinite redirect loop. Then I found this issue.
https://github.com/TryGhost/Ghost/issues/2796 and the problem was that I was missing proxy_set_header X-Forwarded-Proto https; so if you having trouble with infinite redirect loops when using https this could be the problem.

This should be the steps you need to take.

comments powered by Disqus