Too many redirects - docker + nginx proxy_pass

Trying to use docker-compose to run ghost + mysql to host a site. I already have nginx on the host machine (ubuntu 20.04) and I’m trying to use that to pass the ghost site (in docker container).

Everything worked fine over http through the domain but when I used certbot to switch to https, it stopped working with the error: ERR_TOO_MANY_REDIRECTS. I read a lot of similar issues and it seemes like most people were forgetting to pass their headers when doing the proxy_pass. I made sure to do that as you can see below in my nginx file. I’m guessing theres an issue with the docker side but I’m honestly not sure.

nginx site config file:

server {

	server_name esk8.us;

	location / {
    		proxy_set_header X-Real-IP $remote_addr;
    		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    		proxy_set_header Host $http_host;
    		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_pass http://localhost:2368;
	}

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/esk8.us/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/esk8.us/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

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



	server_name esk8.us;


    listen [::]:80;
    listen 80;
    return 404; # managed by Certbot


}

docker-compose.yml:

version: '3'

services:
  ghost:
    image: ghost:latest
    container_name: ghost
    hostname: ghost
    volumes:
      - ./ghost/content:/var/lib/ghost/content:z
    expose:
      - "3306"
    ports:
      - 2368:2368
    environment:
      - NODE_ENV=production
      - url=https://esk8.us
    restart: always
    links:
      - mysql

  mysql:
    image: mysql:latest
    container_name: mysql-ghost
    volumes:
      - ./dbdata:/var/lib/mysql:z 
    expose:
      - "3306"
    environment:
      - MYSQL_ROOT_PASSWORD=<removed>
      - MYSQL_DATABASE=ghostdata
      - MYSQL_USER=ghostusr
      - MYSQL_PASSWORD=<removed>
    restart: always

Chrome network waterfall:

Found the solution here: Bug: Setting url: to https in config.js causes a redirect loop · Issue #2796 · TryGhost/Ghost · GitHub

I needed to set SSL to full (strict) in Cloudflare!

2 Likes