nginx和django配置有问题吗?

时间:2017-12-06 22:12:19

标签: python django nginx devops

我使用NGINX + GUNICORN + DJANGO,我的gunicorn状态有效。 我想用django设置nginx。 我在'mysite'

中创建了一个名为/etc/nginx/sites-available的新文件
server {
        listen 8000 default_server;
        listen [::]:8000 default_server;
        server_name my_ip;
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/split/mysite;
        }
        location / {
            include proxy_params;
            proxy_pass http://unix:/home/split/mysite/mysite.sock;
        }
}

保存并创建指向/etc/nginx/sites-enabled的symbolyc链接 之后我做了sudo service nginx restart并得到了这个:

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

我去了journalctl -xe

-- 
-- Unit nginx.service has finished shutting down.
Dec 07 01:05:17 ubuntu 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.
Dec 07 01:05:17 ubuntu nginx[49646]: nginx: [crit] pread() "/etc/nginx/sites-enabled/sites-available" failed (21: Is a directory)
Dec 07 01:05:17 ubuntu nginx[49646]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 07 01:05:17 ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1
Dec 07 01:05:17 ubuntu sudo[49639]: pam_unix(sudo:session): session closed for user root
Dec 07 01:05:17 ubuntu 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.
Dec 07 01:05:17 ubuntu systemd[1]: nginx.service: Unit entered failed state.
Dec 07 01:05:17 ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
Dec 07 01:05:42 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=02:1e:6d:00:e4:9f:00:01:e8:11:73:69:08:00 SRC=193.124.0.226 DST=194.87.95.46 LEN=48 TOS=0
Dec 07 01:05:57 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=02:1e:6d:00:e4:9f:00:01:e8:11:73:69:08:00 SRC=193.124.0.226 DST=194.87.95.46 LEN=52 TOS=0
Dec 07 01:06:16 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=01:00:5e:00:00:01:00:21:d7:56:a5:80:08:00 SRC=93.95.100.9 DST=224.0.0.1 LEN=32 TOS=0x00 P
Dec 07 01:06:21 ubuntu sudo[49655]:    split : TTY=pts/0 ; PWD=/etc/nginx ; USER=root ; COMMAND=/bin/journalctl -xe
Dec 07 01:06:21 ubuntu sudo[49655]: pam_unix(sudo:session): session opened for user root by split(uid=0)
Dec 07 01:06:39 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=02:1e:6d:00:e4:9f:00:01:e8:11:73:69:08:00 SRC=193.124.0.226 DST=194.87.95.46 LEN=52 TOS=0
Dec 07 01:07:16 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=01:00:5e:00:00:01:00:21:d7:56:a5:80:08:00 SRC=93.95.100.9 DST=224.0.0.1 LEN=32 TOS=0x00 P
Dec 07 01:07:17 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=02:1e:6d:00:e4:9f:00:01:e8:11:73:69:08:00 SRC=185.207.206.224 DST=194.87.95.46 LEN=40 TOS
Dec 07 01:07:46 ubuntu kernel: [UFW BLOCK] IN=eth0 OUT= MAC=02:1e:6d:00:e4:9f:00:01:e8:11:73:69:08:00 SRC=212.16.70.23 DST=194.87.95.46 LEN=40 TOS=0x
Dec 07 01:08:03 ubuntu sudo[49662]:    split : TTY=pts/0 ; PWD=/etc/nginx ; USER=root ; COMMAND=/bin/su
Dec 07 01:08:03 ubuntu sudo[49662]: pam_unix(sudo:session): session opened for user root by split(uid=0)
Dec 07 01:08:03 ubuntu su[49663]: Successful su for root by root
Dec 07 01:08:03 ubuntu su[49663]: + /dev/pts/0 root:root
Dec 07 01:08:03 ubuntu su[49663]: pam_unix(su:session): session opened for user root by split(uid=0)

1 个答案:

答案 0 :(得分:0)

这是我与Uwsgi一起使用的项目草案,对我来说效果很好。只需更改地址 还有一件事将套接字权限更改为664

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///tmp/uwsgi.sock;
    #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      8080;
    # the domain name it will serve for
    server_name 127.0.0.1; # 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 /home/naqib/FINAL_WEB_03/NLLAYVM/media;  # your Django project's media files
    }

    location /static {
        alias /home/naqib/FINAL_WEB_03/NLLAYVM/app/static; # your Django project's static files
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/naqib/FINAL_WEB_03/NLLAYVM/uwsgi_params; # the uwsgi_params file you installed
    }
}