I am trying to deploy and run a django application by using uWSGI, Nginx and docker on DigitalOcean. The Nginx and uWSGI works fine (I think) but I do not know why the uWSGI do not recieve any requests from Nginx.
Here is my nginx configuration
# upstream for uWSGI
upstream uwsgi_app {
server unix:/tmp/uwsgi/my_project.sock;
}
# upstream for Daphne
upstream daphne {
server unix:/tmp/uwsgi/my_project_daphne.sock;
}
server {
listen 80;
server_name www.domaine.com domaine.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /code/django_project/ssl/certs/cert.pem;
ssl_certificate_key /code/django_project/ssl/certs/key.pem
server_name www.domaine.com domaine.com;
error_log stderr warn;
access_log /dev/stdout main;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass uwsgi_app;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_pass http://daphne;
}
location /static/ {
alias /code/django_project/staticfiles/;
}
location /media/ {
alias /code/django_project/mediafiles/;
}
}
my uWSGI file
[uwsgi]
socket = /tmp/uwsgi/my_project.sock
chdir = /code/django_project/
module = django_project.wsgi:application
master = true
processes = 2
chmod-socket = 666
uid = www-data
gid = www-data
harakiri = 60
vacuum = true
buffer-size = 32768
logger = file:/tmp/uwsgi.log
log-maxsize = 200000
**My Dockerfile **
FROM python:3.11.5
### 3. Set environment variables
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /code
COPY . /code/
WORKDIR /code
RUN chmod +x /code/wait-for-it.sh
# uwsgi setup
RUN apk add python3-dev build-base linux-headers pcre-dev
RUN set -e;\
/usr/local/bin/python -m pip install --upgrade pip ;\
python -m pip install --default-timeout=100 -r /code/requirements/deploy.txt ;
CMD ["uwsgi", "--ini", "/code/config/uwsgi/uwsgi.ini"]
My docker-compose.yml file :
services:
app:
image: "${APP_IMAGE}"
restart: unless-stopped
command: >
bash -c "./wait-for-it.sh db:5432 --
&& uwsgi --ini /code/config/uwsgi/uwsgi.ini
&& python /code/django_project/manage.py makemigrations
&& python /code/django_project/manage.py migrate"
volumes:
- .:/code
- /var/log/django_project:/code/logs
- uwsgi_data:/tmp/uwsgi/
environment:
- DJANGO_SETTINGS_MODULE=django_project.settings.test
- POSTGRES_USER=${USER_DB}
- POSTGRES_PASSWORD=${PASSWORD_DB}
- POSTGRES_DB=${DB_NAME}
- POSTGRES_PORT= ${PORT_DB}
env_file:
- .env
networks:
- django_project_network
container_name: app
nginx:
container_name: nginx
restart: unless-stopped
image: "${NGINX_IMAGE}"
ports:
- "80:80"
- "443:443"
volumes:
- uwsgi_data:/tmp/uwsgi/
command: "/bin/sh -c 'while :; do sleep 6h & wait ${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
networks:
- django_project_network
depends_on:
- app
volumes:
uwsgi_data:
networks:
django_project_network:
driver: bridge
In the logs, of docker, that is what I get for app :
[uWSGI] getting INI configuration from /code/config/uwsgi/uwsgi.ini
wait-for-it.sh: waiting 15 seconds for db:5432
wait-for-it.sh: db:5432 is available after 0 seconds
[uWSGI] getting INI configuration from /code/config/uwsgi/uwsgi.ini
wait-for-it.sh: waiting 15 seconds for db:5432
wait-for-it.sh: db:5432 is available after 0 seconds
[uWSGI] getting INI configuration from /code/config/uwsgi/uwsgi.ini
wait-for-it.sh: waiting 15 seconds for db:5432
wait-for-it.sh: db:5432 is available after 0 seconds
[uWSGI] getting INI configuration from /code/config/uwsgi/uwsgi.ini
wait-for-it.sh: waiting 15 seconds for db:5432
wait-for-it.sh: db:5432 is available after 0 seconds
[uWSGI] getting INI configuration from /code/config/uwsgi/uwsgi.ini
2024/06/15 17:32:58 [notice] 9#9: using the "epoll" event method
2024/06/15 17:32:58 [notice] 9#9: nginx/1.23.1
2024/06/15 17:32:58 [notice] 9#9: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2024/06/15 17:32:58 [notice] 9#9: OS: Linux 5.15.0-112-generic
2024/06/15 17:32:58 [notice] 9#9: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/06/15 17:32:58 [notice] 9#9: start worker processes
2024/06/15 17:32:58 [notice] 9#9: start worker process 10
# 2024/06/15 17:34:28 [error] 10#10: *1 open() "/usr/share/nginx/html/index.php" failed (2: No such file or directory), client: 94.73.145.234, server: localhost, request: "GET /index.php?route=extension/module/update/cevap HTTP/1.0", host: "domaine.com"
94.73.145.234 - - [15/Jun/2024:17:34:28 +0000] "GET /index.php?route=extension/module/update/cevap HTTP/1.0" 404 153 "-" "-" "-"
2024/06/15 17:40:08 [error] 10#10: *7 open() "/usr/share/nginx/html/wp-content/plugins/hellopress/wp_filemanager.php" failed (2: No such file or directory), client: 52.169.254.120, server: localhost, request: "GET /wp-content/plugins/hellopress/wp_filemanager.php HTTP/1.1", host: "domaine.com"
52.169.254.120 - - [15/Jun/2024:17:40:08 +0000] "GET /wp-content/plugins/hellopress/wp_filemanager.php HTTP/1.1" 404 153 "-" "-" "-"
2024/06/15 17:40:08 [error] 10#10: *7 open() "/usr/share/nginx/html/lv.php" failed (2: No such file or directory), client: 52.169.254.120, server: localhost, request: "GET /lv.php HTTP/1.1", host: "domaine.com"
52.169.254.120 - - [15/Jun/2024:17:40:08 +0000] "GET /lv.php HTTP/1.1" 404 153 "-" "-" "-"
2024/06/15 17:40:09 [error] 10#10: *7 open() "/usr/share/nginx/html/wp-22.php" failed (2: No such file or directory), client: 52.169.254.120, server: localhost, request: "GET /wp-22.php?sfilename=bdkr28tools.php&sfilecontent=&supfiles= HTTP/1.1", host: "domaine.com"
52.169.254.120 - - [15/Jun/2024:17:40:09 +0000] "GET /wp-22.php?sfilename=bdkr28tools.php&sfilecontent=&supfiles= HTTP/1.1" 404 153 "-" "-" "-"
2024/06/15 17:40:09 [error] 10#10: *7 open() "/usr/share/nginx/html/wp-content/plugins/pwnd/pwnd.php" failed (2: No such file or directory), client: 52.169.254.120, server: localhost, request: "GET /wp-content/plugins/pwnd/pwnd.php HTTP/1.1", host: "domaine.com"
52.169.254.120 - - [15/Jun/2024:17:40:09 +0000] "GET /wp-content/plugins/pwnd/pwnd.php HTTP/1.1" 404 153 "-" "-" "-"
Please can you help me to figure out how to make it work together ? I think that is the main problem. I really need your help. Any answer is welcome. Thanks for advance
I try to read the uwsgi docs and some youtube vidoes but nothing works for me.