Как настроить NGINX и UWSGI в Django
Я развертываю свое приложение Django на VPS и хочу использовать NGINX & UWSGI Я следовал этому руководству https://www.youtube.com/watch?v=ZpR1W-NWnp4 для настройки моего сервера NGINX.
Следующий файл конфигурации моего NGINX называется my_nginx.conf:
# the upstream component nginx needs to connect to
upstream django {
server unix:///root/PIDC/ProjetAgricole/uwsgi_nginx.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 173.249.8.237; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /root/PIDC/ProjetAgricole/media; # your Django project's media files - amend as required
}
location /static {
alias /root/PIDC/ProjetAgricole/staticfiles; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /root/PIDC/ProjetAgricole/uwsgi_params; # the uwsgi_params file you installed
}
}
Я просто изменил пути только в этом файле.
Когда я запускаю эту команду, я получаю такой вывод, который кажется нормальным.
(venv) root@vmi851374:~/PIDC/ProjetAgricole# uwsgi --socket ProjetAgricole.sock --module ProjetAgricole.wsgi --chmod-socket=666
*** Starting uWSGI 2.0.20 (64bit) on [Fri Apr 22 22:36:02 2022] ***
compiled with version: 9.4.0 on 17 April 2022 18:54:03
os: Linux-5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022
nodename: vmi851374.contaboserver.net
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /root/PIDC/ProjetAgricole
detected binary path: /root/my_project/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31601
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address ProjetAgricole.sock fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x561dba821d90
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x561dba821d90 pid: 294717 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 294717, cores: 1)
Но когда я запускаю приложение в браузере, я получаю 502 Bad Gateway. Содержимое файла uwsgi_params следующее:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
Я запутался в этой ошибке. Пожалуйста, помогите мне.