nginx和Django配置有问题吗?

2024-04-28 23:06:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用NGINX+GUNICORN+DJANGO,我的GUNICORN状态为active。 我想用django建立nginx。 我在/etc/nginx/sites-available中创建了一个名为'mysite'的新文件

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得到了这个:

^{pr2}$

我去了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)

Tags: insessionubuntuservicesudonginxrootout
1条回答
网友
1楼 · 发布于 2024-04-28 23:06:50

这是我和uwsgi一起使用的项目草稿,对我来说效果很好。换个地址就行了 还有一件事,把socket权限更改为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
    }
}

相关问题 更多 >