如何用flask和nginx启动uwsgi

时间:2015-03-07 09:54:03

标签: nginx flask uwsgi

我想我的主要问题是我不知道文件层次结构应该是什么样的?到目前为止,我正在他的" Flask开发"中关注格林伯格的教程。书。所以我喜欢:

--manage.py ( Flask's Script extension script)
--app/   ( application folder as a package)
--virtual_env

并且不确定我搞砸了什么,但是现在当我用uwsgi命令尝试一下时,它会说出以下错误:

current working directory: /home/gaucan/temp/my_app
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***

编辑: 像这样开始工作:

uwsgi --http :9090 -w manage:app --enable-threads

这有效...在manage.py我有一句话: app=create_app('default') 所以这就是我想我需要做的......

但是我仍然无法忘记上面的警告......我正在运行uwsgi没有它的主进程管理器......它可以吗?或者我做错了什么?

这只是创建/etc/nginx/nginx.conf文件

    worker_processes 1;

events {

     worker_connections 1024;

}

http {

sendfile on;

gzip              on;
gzip_http_version 1.0;
gzip_proxied      any;
gzip_min_length   500;
gzip_disable      "MSIE [1-6]\.";
gzip_types        text/plain text/xml text/css
                  text/comma-separated-values
                  text/javascript
                  application/x-javascript
                  application/atom+xml;

# Configuration containing list of application servers
upstream uwsgicluster {

    server 127.0.0.1:8080;
    # server 127.0.0.1:8081;
    # ..
    # .

}

# Configuration for Nginx
server {

    # Running port
    listen 80;

    # Settings to by-pass for static files 
    location ^~ /static/  {

        # Example:
        # root /full/path/to/application/static/file/dir;
        root /app/static/;

    }

    # Serve a static file (ex. favico) outside static dir.
    location = /favico.ico  {

        root /app/favico.ico;

    }

    # Proxying connections to application servers
    location / {

        include            uwsgi_params;
        uwsgi_pass         uwsgicluster;

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;

    }
}

}

1 个答案:

答案 0 :(得分:12)

这可能与您安装uwsgi的方式有关。这个警告:

!!! no internal routing support, rebuild with pcre support !!!

与您的应用程序无关,它与您的uwsgi二进制文件无关。

基本上它表示uwsgi的一部分尚未在您使用的二进制文件中启用。运行Flask应用程序不需要该特定功能,因此您可以忽略该警告。但是,如果您想了解更多信息,请参阅this question以获取有关此问题以及如何解决此问题的一些信息。

现在,关于这个其他警告:

*** WARNING: you are running uWSGI without its master process manager ***

我认为您缺少--master选项,以启用prefork服务器。

相关问题