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