简体   繁体   English

如何使用nginx和uwsgi从子目录中提供烧瓶应用程序

[英]How to serve a flask app out of a sub directory with nginx and uwsgi

A problem I ran into recently was how to run a flask app out of a subdirectory. 我最近遇到的一个问题是如何从子目录中运行一个烧瓶应用程序。 For example, you might want mysite.com/myapp to run one flask app and mysite.com/some_other to run another script entirely. 例如,您可能希望mysite.com/myapp运行一个烧瓶应用程序,而mysite.com/some_other则完全运行另一个脚本。 There are a number of good tutorials on the web for how to run a flask app out of mysite.com/, but when I went to solve the subdirectory problem I found some out of date info. 网上有很多关于如何从mysite.com/运行烧瓶应用程序的好教程,但是当我去解决子目录问题时,我发现了一些过时的信息。

When I first started looking into this I found a number of sites advocating that I should put uwsgi_param SCRIPT_NAME /mysubdir and uwsgi_modifier1 30 in the nginx config file. 当我第一次开始研究这个时,我发现有很多网站主张我应该在nginx配置文件中放置uwsgi_param SCRIPT_NAME /mysubdiruwsgi_modifier1 30 Apparently, this is out of date information as of 2017 (nginx nginx/1.10.3 and uwsgi 2.0.15). 显然,这是截至2017年的过时信息(nginx nginx / 1.10.3和uwsgi 2.0.15)。

The config file below is all that is needed for a sub dir. 下面的配置文件是子目录所需的全部内容。

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

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

Next you need to add a few items to the uwsgi ini file. 接下来,您需要在uwsgi ini文件中添加一些项目。 Mine is stored in the same dir as the python files. 我的存储在与python文件相同的目录中。 These are the lines to add. 这些是要添加的行。

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

So the full .ini file now looks like this 所以完整的.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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM