繁体   English   中英

Django部署Gunicorn和NginX

[英]Django deploy Gunicorn and NginX

尝试最终部署我的新流动站Web应用程序时,出现了问题。 我已经配置了Gunicorn并将其绑定到0.0.0.0:80(使用wsgi)。 网站已加载,但没有任何图像,C​​SS,JavaScript文件(即使“ admin”网站也没有任何样式)。 Postgres已安装并运行良好。 我已经做了

python manage.py collectstatic
python manage.py migrate

我看了很多教程如何做到这一点。 但仍然在我尝试运行后:

systemctl status nginx.service

我得到一个错误:

Job for nginx.service failed because the control process exited with error code. 
See "systemctl status nginx.service" and "journalctl -xe" for details.


#systemctl status nginx.service output:

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since śro 2018-11-28 02:57:12 CET; 1min 13s ago
  Process: 14721 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
  Process: 25481 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 25477 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 10279 (code=exited, status=0/SUCCESS)

nginx[25481]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[25481]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[25481]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[25481]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[25481]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[25481]: nginx: [emerg] still could not bind()
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
systemd[1]: nginx.service: Unit entered failed state.
systemd[1]: nginx.service: Failed with result 'exit-code'.




#journalctl -xe output:

sshd[5669]: Received disconnect from 181.15.216.20 port 42140:11: Bye Bye [preauth]
sshd[5669]: Disconnected from 181.15.216.20 port 42140 [preauth]
sudo[5773]: djangosu : TTY=pts/5 ; PWD=/home/djangosu ; USER=root ; COMMAND=/bin/systemctl restart nginx
sudo[5773]: pam_unix(sudo:session): session opened for user root by djangosu(uid=0)
systemd[1]: Stopped A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has finished shutting down.
systemd[1]: Starting A high performance web server and a reverse proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has begun starting up.
nginx[5957]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[5957]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address aginx[5957]: nginx: [emerg] still could not bind()
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
systemd[1]: nginx.service: Unit entered failed state.
systemd[1]: nginx.service: Failed with result 'exit-code'.
sudo[5773]: pam_unix(sudo:session): session closed for user root
sudo[6331]: djangosu : TTY=pts/5 ; PWD=/home/djangosu ; USER=root ; COMMAND=/bin/journalctl -xe
sudo[6331]: pam_unix(sudo:session): session opened for user root by djangosu(uid=0)lready in use)
nginx[5957]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[5957]: nginx: [emerg] still could not bind()
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
systemd[1]: nginx.service: Unit entered failed state.
systemd[1]: nginx.service: Failed with result 'exit-code'.
sudo[5773]: pam_unix(sudo:session): session closed for user root
sudo[6331]: djangosu : TTY=pts/5 ; PWD=/home/djangosu ; USER=root ; COMMAND=/bin/journalctl -xe
sudo[6331]: pam_unix(sudo:session): session opened for user root by djangosu(uid=0)

/etc/systemd/system/gunicorn.socket文件:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

/etc/systemd/system/gunicorn.service文件:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=djangosu
Group=djangosu
WorkingDirectory=/home/djangosu/website/rover-Project
ExecStart=/home/djangosu/website/rover-env/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          rover.wsgi:application

[Install]
WantedBy=multi-user.target

以及网站中可用的“流动站”文件(与项目名称相同)(我已经将其链接到启用了网站的文件):

server {
    listen 80;
    server_name :333 ;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/.../website/rover/rover;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

gunicorn.sock存在于/ run /目录中。...有什么建议吗?

发行公告:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:    16.04
Codename:   xenial

nginx告诉您,它无法绑定到端口80,因为某些其他进程已经在侦听该端口。 您可以在此处的日志输出中看到此内容:

nginx [5957]:nginx:[emerg] bind()到0.0.0.0:80失败(98:地址已在使用中)

要检查哪个进程正在此端口上监听,可以使用netstat或更好的ss

~# ss -naptu state listening | grep :80
tcp   0      128       0.0.0.0:80                    0.0.0.0:*                   users:(("nginx",pid=6824,fd=4),("nginx",pid=6823,fd=4))
~# netstat -tulpen | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          136280382  6823/nginx: master

最后一列将显示进程名称和在端口上侦听的进程的pid。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM