我可以通过在/etc/nginx/nginix.conf文件中将用户替换为root来解决这个问题。
还有另一种设置nginx和gunicorn的方法:
-
gunicorn.service文件(位置:/etc/systemd/system/):
[Unit]
Description=Gunicorn instance to serve algotrading
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/algotrading/oops
Environment="PATH=/home/ubuntu/algotrading/venv/bin"
ExecStart=/home/ubuntu/algotrading/venv/bin/gunicorn --workers 3 --bind unix:algotrading.sock -m 007 wsgi:app
Restart=always
[Install]
WantedBy=multi-user.target
-
Nginx配置文件(位置:/etc/Nginx/sites-available/):
server {
listen 80;
server_name <Public IP>;
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/algotrading/oops/algotrading.sock;
}
}
-
基本命令:
启动Gunicorn服务:
sudo systemctl daemon-reload
sudo systemctl start algotrading
sudo systemctl enable algotrading
sudo systemctl status algotrading
重新启动nginx:
sudo systemctl restart nginx