title: Django w/ Docker, Nginx, Gunicorn and SSL
body: <p>this may be a duplicate but I didn't find a good answer in previous questions, and I am totally new to sysadmin and Django. Docker, Nginx etc. but am trying to troubleshoot HTTPS deployment w/ Django from <a href="https://blog.skindc.co.uk/dockerise-django-and-static-files-with-nginx/" rel="nofollow noreferrer" title="this guide">this guide here</a></p>
  
  <p>The connection to my server isn't working and visiting my FQDN in a browser times out. </p>
  
  <p>Here's my project structure:</p>
  
  <pre><code>project_dir
  ├── assets
  │   └── imgs
  ├── auth
  │   ├── apps.py
  │   ├── auth_forms.py
  │   ├── __init__.py
  │   ├── migrations
  │   ├── __pycache__
  │   ├── urls.py
  │   └── views.py
  ├── changelog_6_3_2018.txt
  ├── changelog.txt
  ├── sub_app1
  │   ├── tests.py
  │   ├── urls.py
  │   ├── views.py
  │   └── wsgi.py
  ├── docker-compose.yml
  ├── Dockerfile
  ├── subapp2
  │   ├── tests.py
  │   ├── urls.py
  │   ├── views.py
  │   └── wsgi.py
  ├── main
  │   ├── admin.py
  │   ├── apps.py
  │   ├── fields.py
  │   ├── forms.py
  │   ├── __init__.py
  │   ├── migrations
  │   ├── models.py
  │   ├── __pycache__
  │   ├── templatetags
  │   ├── tests.py
  │   ├── urls.py
  │   └── views.py
  ├── manage.py
  ├── nginx
  │   ├── nginx.conf
  │   └── nginx.dockerfile
  ├── __pycache__
  │   └── wsgi.cpython-36.pyc
  ├── README.md
  ├── requirements.txt
  ├── sheets
  │   └── LTMonServer.xlsx
  ├── start.sh
  ├── static
  │   ├── admin
  │   └── imgs
  ├── templates
  │   ├── auth
  │   └── fv1
  ├── uwsgi.ini
  ├── venv
  │   ├── bin
  │   ├── lib
  │   ├── pip-selfcheck.json
  │   └── share
  └── wsgi.py
  </code></pre>
  
  <p>Here are my files:</p>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>version: '2'
  services:
  
  
    django:
      container_name: dsne_django
      build:
        context: .
      networks:
        - dsne-django-nginx
      volumes:
        - dsne-django-static:/usr/stc/app/static
      ports:
        - 8000:8000
  
    nginx:
      container_name: dsne-nginx
      build:
        context: ./nginx
        dockerfile: nginx.dockerfile
      networks:
        - dsne-django-nginx
      volumes:
        - dsne-django-static:/usr/src/app/static
        - dsne-nginx-cert:/etc/ssl/certs:ro
      ports:
        - 80:80
        - 443:443
      depends_on:
        - django
  
  volumes:
    dsne-django-static:
    dsne-nginx-cert:
  
  networks:
    dsne-django-nginx:
      driver: bridge
  </code></pre>
  
  <p>main Dockerfile:</p>
  
  <pre><code>FROM python:3.6.4-onbuild
  
  ENV PROJECT_ROOT /usr/src/app
  COPY start.sh /start.sh
  
  # EXPOSE port 8000
  EXPOSE 8000
  EXPOSE 443
  # command to execute to start server
  CMD ["/start.sh"]
  </code></pre>
  
  <p>nginx.conf:</p>
  
  <pre><code>events { worker_connections 1024; }
  
  http {
  
    upstream djangocluster {
      least_conn;
      server django:80;
    }
  
    server {
  
      listen 80;
      log_subrequest on;
      return 301 https://$host$request_uri;
  
    }
  
    server {
  
      listen 443;
      ssl on;
  
      ssl_certificate     /home/johnecker/iba_ltm.pem;
      ssl_certificate_key    /home/johnecker/ibaltm.key;
  
      log_subrequest on;
  
      location / {
        proxy_pass http://djangocluster;
        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-Real-IP $remote_addr;
        proxy_cache_bypass $http_upgrade;
      }
  
      location /static {
          autoindex on;
          alias /usr/src/app/static;
      }
    }
  }
  </code></pre>
  
  <p>nginx Dockerfile:</p>
  
  <pre><code>FROM nginx:1.13.3
  
  # Copy nginx configuration
  COPY nginx.conf /etc/nginx/nginx.conf
  
  # Expose website on ports
  EXPOSE 80
  EXPOSE 443
  
  CMD ["nginx", "-g", "daemon off;"]
  </code></pre>
  
  <p>start.sh:</p>
  
  <pre><code>#!/bin/bash
  # Start Gunicorn processes
  echo Starting Gunicorn.
  
  #make sure we are at project root
  cd $PROJECT_ROOT
  
  
  python manage.py collectstatic --noinput
  cd /usr/src/app
  pip3 install -r requirements2.txt
  
  pwd
  sudo exec gunicorn fv1.wsgi:application -w 3 \
      --bind 0.0.0.0:80 \
      --workers 3 \
  </code></pre>
  
  <p>How can I make this setup work properly for SSL/HTTPS requests? I can't seem to find my error.</p>