title: Docker Compose - https with Nginx/Gunicorn
body: <p>I have the following Nginx config and docker-compose.yaml. Before I adding the following block,</p>
  
  <pre><code>server {
  
    listen 443;
    server_name localhost;
  
    ssl    on;
    ssl_certificate    /etc/nginx/conf.d/privkey.pem;
    ssl_certificate_key    /etc/nginx/conf.d/mynginx.key;
  
    location / {
          proxy_pass http://web/;
      }
  }
  </code></pre>
  
  <p>everything thru HTTP works fine. After I added the above code block, everything stopped working, I can't access the site thru HTTP/HTTPS. </p>
  
  <p><strong>docker-compose logs nginx</strong> output </p>
  
  <pre><code>ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
  </code></pre>
  
  <p><strong>mynginx.conf</strong></p>
  
  <pre><code>upstream web {
    ip_hash;
    server web:8000;
  }
  
  # portal
  server {
    location / {
          proxy_pass http://web/;
      }
    listen 8000;
    server_name localhost;
  }
  
  
  
  # portal (https)
  server {
  
    listen 443;
    server_name localhost;
  
    ssl    on;
    ssl_certificate    /etc/nginx/conf.d/privkey.pem;
    ssl_certificate_key    /etc/nginx/conf.d/mynginx.key;
  
    location / {
          proxy_pass http://web/;
      }
  }
  </code></pre>
  
  <p><strong>docker-compose.yaml</strong></p>
  
  <pre><code>ubuntu@ip-172-31-9-162:~/django_docker$ cat docker-compose.yml
  version: '2'
  services:
    nginx:
      image: nginx:latest
      container_name: ng01
      ports:
        - "80:8000"
        - "443:443"
      volumes:
        - ./src:/src
        - ./config/nginx:/etc/nginx/conf.d
      depends_on:
        - web
    web:
      build: .
      container_name: dg01
      command: bash -c "python manage.py makemigrations &amp;&amp; python manage.py migrate &amp;&amp; gunicorn composeexample.wsgi -b 0.0.0.0:8000"
      depends_on:
        - db
      volumes:
        - ./src:/src
      expose:
        - "8000"
  
    db:
      image: postgres:latest
      container_name: ps01
  </code></pre>
  
  <p><strong>Folder Structure</strong></p>
  
  <pre><code>.
  ├── config
  │   ├── nginx
  │   │   ├── mynginx.conf
  │   │   ├── mynginx.conf~
  │   │   ├── mynginx.crt
  │   │   ├── mynginx.key
  │   │   └── privkey.pem
  │   └── requirements.pip
  ├── docker-compose.yml
  ├── docker-compose.yml~
  ├── Dockerfile
  └── src
      ├── composeexample
      │   ├── __init__.py
      │   ├── __pycache__
      │   │   ├── __init__.cpython-35.pyc
      │   │   ├── __init__.cpython-36.pyc
      │   │   ├── settings.cpython-35.pyc
      │   │   ├── settings.cpython-36.pyc
      │   │   ├── urls.cpython-35.pyc
      │   │   ├── urls.cpython-36.pyc
      │   │   ├── wsgi.cpython-35.pyc
      │   │   └── wsgi.cpython-36.pyc
      │   ├── settings.py
      │   ├── settings.py~
      │   ├── urls.py
      │   └── wsgi.py
      ├── db.sqlite3
      └── manage.py
  </code></pre>