我正在尝试使用 nginx 和 gunicorn 部署 django 应用程序,但显示错误
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl status gunicorn.service
gunicorn.service - gunicorn service
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset:
Active: active (running) since Sat 2020-04-11 21:19:19 IST; 11s ago
Main PID: 16326 (gunicorn)
Tasks: 4 (limit: 1689)
sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-04-11 04:54:18 IST; 18h ago
Docs: man:nginx(8)
Process: 1650 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfi
Process: 1652 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exite
Process: 1651 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (c
Main PID: 1653 (nginx)
Tasks: 9 (limit: 1689)
CGroup: /system.slice/nginx.service
├─1653 nginx: master process /usr/sbin/nginx -g daemon on; master_process o
├─1654 nginx: worker process
├─1655 nginx: worker process
├─1656 nginx: worker process
├─1657 nginx: worker process
├─1658 nginx: worker process
├─1659 nginx: worker process
├─1660 nginx: worker process
└─1661 nginx: worker process
Apr 11 04:54:18 wms systemd[1]: Starting A high performance web server and a reverse p
Apr 11 04:54:18 wms systemd[1]: Started A high performance web server and a reverse pr
已经尝试过
sudo systemctl stop nginx && sudo systemctl disable nginx && sudo systemctl enable nginx && sudo systemctl start nginx
/etc/nginx/sites-available/iitians
server {
listen 80;
server_name 192.95.37.123;
location = /images/favicon.ico {access_log off;log_not_found off;}
location /static/ {
root /home/wms/iitians;
}
location /media/ {
root /home/wms/iitians;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/wms/iitians/iitians.sock;
}
}
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn service
After=network.target
[Service]
User=wms
Group=www-data
WorkingDirectory=/home/wms/iitians/
ExecStart=/home/wms/iitiansenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/wms/iitians/iitans.sock iitians.wsgi:application
[Install]
WantedBy=multi-user.target
答案1
启动 gunicorn 后,我建议您先用以下命令测试网关:
sudo -u <nignx-user> curl --unix-socket /home/wms/iitians/iitians.sock http
这
proxy_pass http://unix:/home/wms/iitians/iitians.sock;
应该
proxy_pass unix:/home/wms/iitians/iitians.sock;