V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
codeface
V2EX  ›  问与答

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

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

    服务器为 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   ·   我们的愿景   ·   实用小工具   ·   2543 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:35 · PVG 23:35 · LAX 08:35 · JFK 11:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.