【问题标题】:How to serve a flask app out of a sub directory with nginx and uwsgi如何使用 nginx 和 uwsgi 从子目录中提供烧瓶应用程序
【发布时间】:2017-10-02 05:51:07
【问题描述】:

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

【问题讨论】:

    标签: python nginx flask uwsgi


    【解决方案1】:

    当我第一次开始研究这个问题时,我发现许多网站主张我应该将 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
    

    【讨论】:

    • 即使我从 ini 文件中删除 module = wsgi:application,它似乎也对我有用。
    猜你喜欢
    • 2015-09-18
    • 2012-11-28
    • 2015-05-08
    • 2019-04-05
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多