Nginx+uWSGI+Flask 配置失败,求教 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
codeface
14.49D
V2EX    问与答

Nginx+uWSGI+Flask 配置失败,求教

  •  
  •   codeface 2016-01-10 13:08:43 +08:00 2840 次点击
    这是一个创建于 3570 天前的主题,其中的信息可能已经有所发展或是发生改变。

    服务器为 centOS 7.0
    Python 版本为 3.5
    uWSGI 版本为 2.0.12
    Ngnix 版本为 1.9.9
    Flask 也是最新版

    按下面的配置运行后,访问首页能正常显示 Hello world ,但访问 /about 显示 404 。

    app.py 内容如下

    from flask import Flask app = Flask(__name__) @app.route("/") def index(): return("Hello world") @app.route("/about") def about(): return("this is a test") if __name__ == "__main__": app.run() 

    uwsgi.ini 如下

    [uwsgi] # uwsgi 启动时所使用的地址与端口 socket = 127.0.0.1:3031 chdir = /home/www/app wsgi-file = app.py callable = app # 处理器数 processes = 4 # 线程数 threads = 2 #状态检测地址 stats = 127.0.0.1:9191 #守护进程 daemOnize= /var/log/uwsgi/uwsgi.log 

    /usr/local/nginx/conf/nginx.conf 如下:

    events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name 127.0.0.1; #charset koi8-r; access_log logs/host.access.log main; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:3031; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 

    自己测试修改,觉得应该是 ngnix 的配置问题。
    搜了很多资料,有提到修改 /etc/nginx/sites-enabled/default 这个文件的,但我没有找到这个路径。

    谁能帮我看看,不胜感激。

    3 条回复    2016-01-19 19:42:44 +08:00
    codeface
        1
    codeface  
    OP
       2016-01-10 14:15:30 +08:00
    [pid: 14935|app: 0|req: 78/128] 220.180.56.180 () {48 vars in 787 bytes} [Sun Jan 10 14:12:09 2016] GET / => generated 14 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)

    [pid: 14935|app: 0|req: 79/129] 220.180.56.180 () {46 vars in 766 bytes} [Sun Jan 10 14:12:13 2016] GET /about => generated 233 bytes in 1 msecs (HTTP/1.1 404) 2 headers in 72 bytes (1 switches on core 0)

    这是 uwsgi 打出来的 log
    codeface
        2
    codeface  
    OP
       2016-01-10 14:19:32 +08:00
    貌似找到原因了。
    修改 uwsgi 的配置文件后,
    使用 /usr/local/python3/bin/uwsgi --reload /home/codeface/app/uwsgi_conf.ini 重新加载配置文件并没有起作用。
    kill 掉 uwsgi 的进程,重新启动就好了。
    qq3102328040
        3
    qq3102328040  
       2016-01-19 19:42:44 +08:00   1
    受人之托,来挽个尊
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2495 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 05:47 PVG 13:47 LAX 22:47 JFK 01:47
    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