Score:0

Django deploy with Gunicorn, Nginx and Docker-Compose returns Server Error 500

vi flag

I'm deploying a Django application on ubuntu server, where I have installed Nginx. The app is deployed using docker-compose and gunicorn.

Here's my nginx configuration:

upstream backend {
    server 0.0.0.0:8000;
}

server {
    index index.html index.htm index.nginx-debian.html;
    server_name www.example.com example.com;

    location / {
        root /home/user/project/web;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    location /api/ {
        proxy_pass http://backend/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /media/ {
        autoindex off;
        alias /home/user/project/backend/media/;
    }

    location /staticfiles/ {
        autoindex off;
        alias /home/user/project/backend/staticfiles/;
    }

    location ~ /\. {
        deny all;
    }
}

And here's my Django views:

def index(request):
    return render(request, "landing.html")

@api_view(["POST"])
@permission_classes([AllowAny])
def create_user(request):
    data = request.data
    ...

So when calling: https://example.com/api/ it works, returning the content of the html file. But when try to call the second view with https://example.com/api/create/ it shows 500 internal server error, and in the docker console I can see the log of the error, so it reach the server.

And finally a slice of my docker-compose file for the django app:

services:
  app:
    build: .
    command: uvicorn real.asgi:application --host 0.0.0.0 --port 8000
    volumes:
      - .:/code
    env_file:
      - ./.env/dev.env
    ports:
      - 8000:8000
    depends_on:
      - database
      - redis
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.