django+uwsgi+nginx 访问出错 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
crazycabbage

django+uwsgi+nginx 访问出错

  •  
  •   crazycabbage May 13, 2016 5438 views
    This topic created in 3639 days ago, the information mentioned may be changed or developed.
    报错如下:
    2016/05/13 19:02:40 [error] 11057#0: *162 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /poweredby.png HTTP/1.1", upstream: "uwsgi://127.0.0.1:8003", host: "xxx.xxx.xxx.xxx:8000", referrer: "http://xxx.xxx.xxx.xxx:8000/" 
    uwsgi 配置如下:
    [uwsgi] socket = 127.0.0.1:8003 touch-reload=/myblog/reload processes = 2 threads = 4 vacuum = true 
    nginx 配置如下:
     server { listen 8000; server_name xxx.xxx.xxx.xxx; root /usr/share/nginx/html; access_log /logs/access.log; error_log /logs/error.log; charset utf-8; # Load configuration files for the default server block. location / { include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:8003; client_max_body_size 35m; uwsgi_param UWSGI_SCRIPT myblog.wsgi; uwsgi_param UWSGI_CHDIR /myblog; } location /media { alias /path/to/project/media; } location /static { alias /path/to/project/static; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } 
    views.py 文件内容
    #coding:utf-8 from django.shortcuts import render from django.http import HttpResponse # Create your views here. def index(request): return HttpResponse(u"Hello World!!") 

    搞了一天了,死活连不上, uwsgi8003 端口正常访问, nginx 代理 8000 端口连不上,端口已经开放,防火墙已经关闭,求解,感激不尽!

    13 replies    2016-05-15 01:01:32 +08:00
    peter999
        1
    peter999  
       May 13, 2016
    selinux
    peter999
        2
    peter999  
       May 13, 2016
    nginx 监听的 ip 是不是写成本地了,保险的话写成 0.0.0.0
    pc10201
        3
    pc10201  
       May 13, 2016
    先直接用 uwsgi 跑 django 试一下,没有问题再与 nginx 一起开
    crazycabbage
        4
    crazycabbage  
    OP
       May 13, 2016
    @peter999 写的是 0.0.0.0
    crazycabbage
        5
    crazycabbage  
    OP
       May 13, 2016
    @pc10201 uwsgi 跑是能成功的,端口是 8003 , nginx 端口是 8000
    peter999
        6
    peter999  
       May 13, 2016
    配置个静态目录看能访问到吗,还有目录和文件权限问题
    peter999
        7
    peter999  
       May 13, 2016
    如果你有路由器又是通过外网 ip 访问,还要检查下路由器上端口是不是被别的机器占用了
    crazycabbage
        8
    crazycabbage  
    OP
       May 13, 2016
    @peter999 没有用路由器,端口换了也没用,根据错误日志是 upstream timed out (110: Connection timed out) while reading response header from upstream ,超时,谜一样
    zwzmzd
        9
    zwzmzd  
       May 14, 2016 via Android
    如果直接用 uwsgi 作前端,会有什么问题么?长期裸跑 uwsgi 的路过
    wizardoz
        10
    wizardoz  
       May 14, 2016
    你有没有搞错? 8003 端口正常访问?
    nginx 访问 uwsgi 用的是 wsgi 协议,浏览器访问 uwsgi 用的是 http 哦。
    wizardoz
        11
    wizardoz  
       May 14, 2016
    把配置文件中的
    socket = 127.0.0.1:8003
    改成
    uwsgi-socket = 127.0.0.1:8003
    试试

    或者手动起 uwsgi ,再用 nginx 反代过来试试。
    wizardoz
        12
    wizardoz  
       May 14, 2016
    然后再把
    uwsgi-socket = 127.0.0.1:8003
    改成
    uwsgi-socket = 0.0.0.0:8003
    试试
    crazycabbage
        13
    crazycabbage  
    OP
       May 15, 2016
    @wizardoz 谢谢了,已经解决了,估计是 uwsgi_param UWSGI_SCRIPT myblog.wsgi;uwsgi_param UWSGI_CHDIR /myblog;这个问题,我是用 supervisor 来管理的
    About     Help     Advertise     Blog     API     FAQ     Solana     2649 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 43ms UTC 03:34 PVG 11:34 LAX 20:34 JFK 23:34
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86