小白求助 Django+uWSGI+nginx 部署时,通过 uWSGI 的端口的可以访问, Nginx 404,在线等大佬

2019-02-16 16:31:10 +08:00
 diangdiang

是哪里配置的不对吗,折腾了好久,等大佬帮忙~

mysite_nginx.conf 文件

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/lee/code/toyinstagram/bookmarks/mysite.sock; # for a file socket
    # 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      9310;
    # 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/lee/code/toyinstagram/bookmarks/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/lee/code/toyinstagram/bookmarks/account/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/lee/code/toyinstagram/bookmarks/uwsgi_params; # the uwsgi_params file you installed
    }
}

uWSGI

uwsgi.ini 文件

[uwsgi]
http = :9310
# the local unix socket file than commnuincate to Nginx
socket = /home/lee/code/toyinstagram/bookmarks/mysite.sock
# the base directory (full path)
chdir = /home/lee/code/toyinstagram/bookmarks
# Django's wsgi file
wsgi-file = bookmarks/wsgi.py
# maximum number of worker processes
processes = 4
#thread numbers startched in each worker process
threads = 2
 
#monitor uwsgi status
stats = 127.0.0.1:9191
# clear environment on exit
vacuum          = true

80 端口 404




9310 端口 可正常访问

5067 次点击
所在节点    程序员
46 条回复
diangdiang
2019-02-16 21:20:11 +08:00
@Lax 嗯 目前是这样配的 还是 有问题
mysite_nginx.conf 里的
location / {
uwsgi_pass django; # 这里是不是有问题,我看有的不是这样配的,但是换成 127.0.0.1:uwsgi 的端口 也不行诶
include /home/lee/code/toyinstagram/bookmarks/uwsgi_params; # the uwsgi_params file you installed
}
cepro
2019-02-16 21:50:35 +08:00
1.权限问题。
2.重启 nginx。
3.检查一下自己的路径。(有时候多一个"/"或者少一个就不一样了)
4.setting 文件里面的 DEBUG 和 HOST 是否正确。

可以通过看 nginx 的错误日志来分析分析。
ushuz
2019-02-16 22:26:12 +08:00
你的 uwsgi 监听端口用的是 http 协议,nginx 反代应该用 `proxy_pass`。如果要用 `uwsgi_pass`,那 uwsgi 配置应该把 `http = :9310` 换成 `socket = :9310`
diangdiang
2019-02-16 23:01:44 +08:00
@ushuz 嗯 这里改了, 老哥帮忙看下一下 主题附言 部分的 最新配置文件还有什么问题吗 还是不行诶
theks
2019-02-17 11:50:28 +08:00
我没仔细看你的需求描述,感觉上应该是你的 django 程序已经正常运行在 9310 端口,只需要 nginx 做个反向代理就行。
server {
listen 80;
#server_name 152.136.39.150; #这里写你自己的域名或者 ip 或者其它主机头
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:9310;
}

}
BooksE
2019-02-17 16:31:18 +08:00
先看 nginx 的 log,我以前出现类似情况( uwsgi 通,nginx 不通)是因为防火墙的问题,把防火墙关了就成功了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/535647

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX