【问题标题】:Flask, nginx, and uwsgi烧瓶、nginx 和 uwsgi
【发布时间】:2012-11-28 08:07:43
【问题描述】:

我的烧瓶应用看起来像这样...
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 这是输出

*** 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 错误......我该如何解决这个问题?

【问题讨论】:

    标签: python nginx flask uwsgi


    【解决方案1】:

    unix 套接字是文件系统对象,因此 nginx 需要对 /tmp/uwsgi.sock 的写入权限

    您正在以 root 身份运行 uWSGI(为什么???),因此 /tmp/uwsgi.sock 将归 root 所有,而 nginx 通常以没人或 www-data 身份运行。

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

    【讨论】:

      【解决方案2】:

      你可以看看这个:Python flask with Nginx and uWSGI 因为 repo 提供了关于如何在生产模式下使用 Flask 的确切案例/场景。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-16
        • 2015-05-08
        • 2019-09-29
        • 2016-03-20
        • 2018-02-02
        • 2013-09-01
        • 2013-08-03
        相关资源
        最近更新 更多