微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flask,nginx和uwsgi

我的烧瓶应用看起来像这样…

myapp.py

from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run('0.0.0.0')

我的Nginx设置

server { root /home/admin.jeremylspencer.com; server_name admin.jeremylspencer.com; location / { try_files $uri @yourapplication; } location @yourapplication { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } #error_page 404 /404.html; #error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/Nginx/www; } location ~ /.ht { allow all; } }

然后最后我重新启动Nginx并运行这个:

sudo uwsgi -s /tmp/uwsgi.sock –module myapp –callable app这是输出

使用Flask + Nginx根据dynamicURL提供静态文件

Nginx + uwsgi + flask – 禁用自定义错误页面

Nginx + uWsgi + Flask应用程序性能testing

Nginx和Flask-socketio Websockets:活着但不是消息?

简单的networkingUDP收听烧瓶或金字塔

*** Starting uWsgi 1.4.3 (64bit) on [Mon Dec 10 15:41:00 2012] *** compiled with version: 4.6.3 on 10 December 2012 13:06:15 os: Linux-3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 nodename: jeremylspencer.com machine: x86_64 clock source: unix detected number of cpu cores: 2 current working directory: /home/admin.jeremylspencer.com detected binary path: /usr/local/bin/uwsgi uWsgi running as root,you can use --uid/--gid/--chroot options *** WARNING: you are running uWsgi as root !!! (use the --uid flag) *** *** WARNING: you are running uWsgi without its master process manager *** your processes number limit is 31285 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes uwsgi socket 0 bound to UNIX address /tmp/uwsgi.sock fd 3 Python version: 2.7.3 (default,Aug 1 2012,05:25:23) [GCC 4.6.3] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x1dfa790 your server socket listen backlog is limited to 100 connections mapped 72392 bytes (70 KB) for 1 cores *** Operational MODE: single process *** Wsgi app 0 (mountpoint='') ready in 0 seconds on interpreter 0x1dfa790 pid: 13645 (default app) *** uWsgi is running in multiple interpreter mode *** spawned uWsgi worker 1 (and the only) (pid: 13645,cores: 1)

但是,我所得到的是一个502错误…任何我如何解决这个问题?

如何终止作为服务运行的应用程序?

改变静态文件服务从烧瓶Nginx

UndefinedError:'user'未定义

我如何在Python的后台运行一个长时间运行的工作

在EC2实例中使用Wsgi来托pipeFlask应用程序时出现问题

unix套接字是文件系统对象,所以Nginx需要对/tmp/uwsgi.sock写入权限

你以超级用户身份运行uWsgi(为什么?),所以/tmp/uwsgi.sock将由root拥有,而Nginx通常以nobody或www-data身份运行。

如果你不想考虑使用TCP套接字的权限,但显然不要以root身份运行你的应用程序。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐