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

2016-01-10 13:08:43 +08:00
 codeface

服务器为 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 这个文件的,但我没有找到这个路径。

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

2229 次点击
所在节点    问与答
3 条回复
codeface
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
2016-01-10 14:19:32 +08:00
貌似找到原因了。
修改 uwsgi 的配置文件后,
使用 /usr/local/python3/bin/uwsgi --reload /home/codeface/app/uwsgi_conf.ini 重新加载配置文件并没有起作用。
kill 掉 uwsgi 的进程,重新启动就好了。
qq3102328040
2016-01-19 19:42:44 +08:00
受人之托,来挽个尊

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

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

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

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

© 2021 V2EX