# django with nginx reverse proxy in docker compose

**URL:** <https://forum.djangoproject.com/t/django-with-nginx-reverse-proxy-in-docker-compose/20667>\
**Category:** Deployment\
**Created:** [May 2, 2023, 2:27am UTC](https://forum.djangoproject.com/t/django-with-nginx-reverse-proxy-in-docker-compose/20667 "2023-05-02T02:27:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julianov](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/julianov/32/3502_2.png) [@julianov](https://forum.djangoproject.com/u/julianov)\
**Post date:** [May 2, 2023, 2:27am UTC](https://forum.djangoproject.com/t/django-with-nginx-reverse-proxy-in-docker-compose/20667/1 "2023-05-02T02:27:44Z")

</div>

I am having problems configuring docker compose, being more specific in the nginx configuration since when I want to consume the API it returns the following

running

> docker logs webserver-callservices

> [01/May/2023:19:41:53 +0000]  
> “\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x03d\x1F\xC3\x01\x8D\xEF\xADz-\xD2Me\xA1\x01\x09Rbd\x93\xED\xCA\xEB\xD6”  
> 400 157 “-” “-”

But running

> docker logs callservicebackend-backendcallservices-1

I get

> Watching for file changes with StatReloader Performing system  
> checks…
> 
> System check identified no issues (0 silenced). May 01, 2023 -  
> 17:01:54 Django version 3.0, using settings ‘callservices.settings’  
> Starting development server at [http://0.0.0.0:8000/](http://0.0.0.0:8000/) Quit the server  
> with CONTROL-C.

From what I understand there is a problem in the nginx configuration

this is the docker-compose.yml

```
version: '3.8'

services:
  webservercallservices:
    image: nginx:latest
    container_name: webserver-callservices
    restart: always
    depends_on:
      - backendcallservices
    ports:
      - "443:443"
    volumes:
      - ./:/var/www
      - ./Dockerfiles/nginx:/etc/nginx/conf.d
      - /etc/letsencrypt:/etc/letsencrypt 
    networks:
      app-network:

  backendcallservices:
    build:
      context: ./Dockerfiles/python
      dockerfile: Dockerfile
    command: sh -c 'python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000'
    volumes:
      - ./:/code
    ports:
      - "8000:8000"
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    depends_on:
      - databasecallservices
      - redis
    networks:
      app-network:

  celery:
    build:
      context: ./Dockerfiles/python
      dockerfile: Dockerfile
    command: celery -A callservices worker -l info
    volumes:
      - ./:/code
    depends_on:
      - databasecallservices
      - redis
    environment:
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    networks:
      app-network:

  redis:
    image: redis:latest
    container_name: redis
    restart: always
    ports:
      - "6379:6379"
    networks:
      app-network:

  databasecallservices:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    ports:
      - "5432:5432"
    networks:
      app-network:

networks:
  app-network:

```

This is the config of nginx

```
server {
    listen 443 ssl;
    index index.html;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;

    ssl_certificate /etc/letsencrypt/live/xxxx.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xxxx.com/privkey.pem;

    location / {
        proxy_pass http://backendcallservices:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

```

Is it possible that the problem is because django doesn’t have https?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 2, 2023, 3:02am UTC](https://forum.djangoproject.com/t/django-with-nginx-reverse-proxy-in-docker-compose/20667/2 "2023-05-02T03:02:44Z")

</div>

In this situation, nginx is your ssl endpoint - it should be talking straight http to your backend. Django doesn’t _need_ to handle any part of the ssl.

Do you have any other `location` sections in your nginx config file?

What (if anything) does your nginx error.log file show? How about the access.log? Does it look like it’s the right url being submitted?

Note, you should **not** be using runserver for `backendcallservices`. You should be using either uwsgi, gunicorn, or some other “production-ready” wsgi service.

(Side note: Your compose file and your nginx conf file are both very similar to what we use for the same purposes.)
