如何使用nginx和uwsgi

时间:2017-10-02 05:51:07

标签: python nginx flask uwsgi

我最近遇到的一个问题是如何从子目录中运行一个烧瓶应用程序。例如,您可能希望mysite.com/myapp运行一个烧瓶应用程序,而mysite.com/some_other则完全运行另一个脚本。网上有很多关于如何从mysite.com/运行烧瓶应用程序的好教程,但是当我去解决子目录问题时,我发现了一些过时的信息。

1 个答案:

答案 0 :(得分:2)

当我第一次开始研究这个时,我发现有很多网站主张我应该将uwsgi_param SCRIPT_NAME /mysubdiruwsgi_modifier1 30放在nginx配置文件中。显然,这是截至2017年的过时信息(nginx nginx / 1.10.3和uwsgi 2.0.15)。

以下配置文件是子目录所需的全部内容。

server {
    listen 80;
    server_name wf.idt.com;

    location /mysubdir {
        include           /etc/nginx/uwsgi_params;
        uwsgi_pass        unix:///var/python/myapp/myapp.sock;
    }
}

接下来,您需要在uwsgi ini文件中添加一些项目。我的存储在与python文件相同的目录中。这些是要添加的行。

## Settings to deal with the subdirectory
manage-script-name = true
mount=/mysubdir=wsgi.py

所以完整的.ini文件现在看起来像这样

[uwsgi]
module = wsgi:application
#location of log files
logto = /var/log/uwsgi/app/%n.log
master = true
processes = 5
## Settings to deal with the subdirectory
manage-script-name = true
mount=/myapp=wsgi.py
socket = myapp.sock
chmod-socket = 660
vacuum = true
die-on-term = true