Peter Souter
Peter Souter

Reputation: 5190

docker-compose error with ghost and an nginx proxy

So, I'm getting started with docker-compose

Right now, I'm having an issue with nginx proxying requests.

So I have a container which uses the ghost image and is exposed on 2368:

ghostblog:
  container_name: ghostblog
  image: ghost
  restart: always
  ports:
    - 2368:2368
  env_file:
    - ./config.env
  volumes:
    - "./petemsGhost/content/themes:/usr/src/ghost/content/themes"
    - "./petemsGhost/content/apps:/usr/src/ghost/content/apps"
    - "./petemsGhost/content/images:/usr/src/ghost/content/images"
    - "./petemsGhost/content/data:/usr/src/ghost/content/data"
    - "./petemsGhost/config:/var/lib/ghost"

And I'm linking that to an nginx container that is proxying requests to the container:

ghost_nginx:
  restart: always
  build: ./ghostNginx/
  ports:
    - 80:80
    - 443:443
  links:
    - 'ghostblog:ghostblog'

Inside that build, I copy over a bunch of stuff, keys, config etc:

Dockerfile

FROM centos:centos6
# Delete defaults
RUN yum install epel-release -y
RUN yum install -y nginx curl
RUN rm /etc/nginx/nginx.conf
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/nginx.conf
COPY sites-enabled/petersouter.co.uk.conf /etc/nginx/sites-available/petersouter.co.uk.conf
COPY conf.d/ghost_blog_petersouter.co.uk-upstream.conf /etc/nginx/conf.d/ghost_blog_petersouter.co.uk-upstream.conf
COPY petersouter.co.uk.crt /etc/nginx/petersouter.co.uk.crt
COPY petersouter.co.uk.key /etc/nginx/petersouter.co.uk.key

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]

/etc/nginx/conf.d/ghost_blog_petersouter.co.uk-upstream.conf

upstream ghost_blog_petersouter.co.uk {
  server     ghostblog:2368  fail_timeout=10s;
}

/etc/nginx/sites-enabled/petersouter.co.uk.conf

# Redirect all non-SSL to SSL
server {
  listen         0.0.0.0:80;
  return         301 https://$server_name$request_uri;
}

# Main SSL Config Block
server {
  listen         0.0.0.0:443 ssl;

  ssl on;

  ssl_certificate           /etc/nginx/petersouter.co.uk.crt;
  ssl_certificate_key       /etc/nginx/petersouter.co.uk.key;
  ssl_session_cache         shared:SSL:10m;
  ssl_session_timeout       5m;
  ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers               ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
  ssl_prefer_server_ciphers on;

  index  index.html index.htm index.php;

  access_log            /var/log/nginx/ssl-petersouter.co.uk.access.log combined;
  error_log             /var/log/nginx/ssl-petersouter.co.uk.error.log;

  location / {
    proxy_pass            http://ghost_blog_petersouter.co.uk;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_buffering off;
  }

}

And the linking is working, because I can see it in the nginx container:

 $ docker exec -i -t petersouterblogcompose_ghost_nginx_1 bash
 $ curl ghostblog:2368
 $ Moved Permanently. Redirecting to https://petersouter.co.uk/

And outside of the container I can curl the ghost instance directly:

 $ curl 0.0.0.0:2368
 $ Moved Permanently. Redirecting to https://petersouter.co.uk/

But when I try to go to port 80 that redirects correctly, I get no response:

$ curl curl 0.0.0.0:80
$ curl: (52) Empty reply from server

I'm guessing that I've messsed something up in the nginx config somewhere, as everything else seems to be working as intended.

Upvotes: 2

Views: 466

Answers (1)

Peter Souter
Peter Souter

Reputation: 5190

Worked it out, it's always the simple things!

Note this line of the nginx Dockerfile:

COPY sites-enabled/petersouter.co.uk.conf /etc/nginx/sites-available/petersouter.co.uk.conf

I'm copying into the sites-available folder, so the conf is never getting loaded! Fixed that:

COPY sites-enabled/petersouter.co.uk.conf /etc/nginx/sites-enabled/petersouter.co.uk.conf

And everything worked! :)

Upvotes: 3

Related Questions