小白求助 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 端口 可正常访问

4868 次点击
所在节点    程序员
46 条回复
diangdiang
2019-02-16 16:32:02 +08:00
求别沉,卡了好久了
746970179
2019-02-16 16:36:46 +08:00
好像 nginx 中的 listen 的端口, 就是 nginx 的端口
你要是想访问 80, nginx 的 listen 端口改成 80, 然后重启 nginx 试一下呢
blless
2019-02-16 16:44:51 +08:00
nginx 版本这么老…那个 80 可能是默认配置文件监听的吧?检查一下 nginx 跟 uwsgi 的日志先?我怀疑你这 nginx 压根没用上
diangdiang
2019-02-16 16:46:47 +08:00
@746970179 不行呢,按照上面的配置文件,nginx 监听是 80 端口
是不是 client 通过 80 端口 访问 nginx,nginx 通过 9310 和 uWSGI 通信,这块一直没搞太清楚
<img src="https://i.loli.net/2019/02/16/5c67cdd8c3a30.jpg">
diangdiang
2019-02-16 16:48:11 +08:00
@blless 请求过来的时候 nginx 有日志输出,但是 uwsgi 控制台没有,感觉是请求 到了 nginx,但是 没到 uwsgi
wukui
2019-02-16 16:51:24 +08:00
nginx 配置文件中的 server_name 127.0.0.1; 应该只能在 nginx 运行的机器上访问 http://127.0.0.1:9310/ 。 如果你想在除了 nginx 运行机器以外打开,需要在 server_name 127.0.0.1; 这个配置加上你服务器 IP 或者域名。 不知道是不是你要的答案。
diangdiang
2019-02-16 16:53:55 +08:00
@wukui 改成服务器自己的 ip 还是不行🤣
neoblackcap
2019-02-16 16:57:25 +08:00
两个服务的端口都重复了,你将 nginx 配置里面的 listen 改为 80 吧
diangdiang
2019-02-16 17:01:36 +08:00
@neoblackcap 改成 80 了 还是 404,请求的时候 nginx 有日志,但是 uwsgi 控制台没有🤣
diangdiang
2019-02-16 17:06:26 +08:00
@neoblackcap 感觉是不是 请求到了 nginx,但是 nginx 和 uwsgi 通信 出了问题,没到 uwsgi,uwsgi 控制台也没有相关的输出
diangdiang
2019-02-16 17:08:21 +08:00
@neoblackcap 单独访问 9310 的端口,可以通过 uwsgi 正常访问到,uwsgi 控制台也有输出🤣
NeverBelieveMe
2019-02-16 17:29:50 +08:00
你查一下 nginx+uwsgi 配置。你这个 nginx 配置不对。
NeverBelieveMe
2019-02-16 17:31:20 +08:00
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

location /{
include uwsgi_params;
uwsgi_pass 127.0.0.1:5000;

}

}
NeverBelieveMe
2019-02-16 17:32:06 +08:00
上面是 nginx+uwsgi+flask 的配置的时候 nginx 的配置
ytmsdy
2019-02-16 17:33:53 +08:00
# the port your site will be served on
listen 9310;

这里应该是 80 吧。。。。
你试试本地的 9310 端口能不能访问。
zqyisasd
2019-02-16 17:36:27 +08:00
我的配置 django.conf
upstream django {
server 192.168.115.21:8111;
}
server {
listen 80;
server_name 192.168.115.21;
location / {
uwsgi_pass unix:/usr/share/nginx/django_monitor/uwsgi.sock;
include /etc/nginx/uwsgi_params;
index /ad/login/;
}
}
uwsgi.ini
[uwsgi]
socket = 0.0.0.0:8111
chdir = /usr/share/nginx/django_monitor/monitor/
module = monitor.wsgi
master = true
processes = 1
threads=2
chmod-socket = 666
vacuum = true
static-map=/static=/usr/share/nginx/django_monitor/monitor/static
uid=nginx
gid=nginx
socket=/usr/share/nginx/django_monitor/uwsgi.sock
enable-threads = true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=1024
max-requests = 1024
diangdiang
2019-02-16 17:39:46 +08:00
@ytmsdy 改成 80 了也不行 🤣
Humorce
2019-02-16 17:45:56 +08:00
那么为什么不贴 nginx 的日志呢
JoyBanana
2019-02-16 17:51:23 +08:00
没有人监听 80 端口,nginx 报 404 很正常吧。uWSGI 和 nginx 都监听 9310 吗?
diangdiang
2019-02-16 17:51:41 +08:00
@zqyisasd
Hi 老哥,想问一下, 8111 是配置 uwsgi 前,调试 django 用的接口吗
另外 uwsgi.ini 文件的 socket 的值 是不是被覆盖了🤣
<img src="https://i.loli.net/2019/02/16/5c67dc9541cdd.jpg">

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

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

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

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

© 2021 V2EX