Django和Flask放在同一个nginx s上

2024-04-27 13:17:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前有一个Djago应用程序运行在我的主网站,当我访问mysite.com网站. 不过,我想mysite.com/flaskapp运行单独的烧瓶应用程序。我可以设置两个支持nginx站点的配置文件,并在不同的端口上运行每个应用程序,但是出于各种原因,我希望在同一个端口上运行它们(如果可能)。当我在nginx服务器文件中配置我的flaskapp/位置时,我得到一个404错误。在

这是我的主管配置文件:

[program:MYSITE]
command=/var/www/html/MYSITE/prodenv/bin/gunicorn --workers 3 --bind unix:/var/www/html/MYSITE/public_html/MYSITE.sock MYSITE.wsgi
directory=/var/www/html/MYSITE/public_html
autostart=true
autorestart=true
stderr_logfile=/var/log/MYSITE.err.log
stdout_logfile=/var/log/MYSITE.out.log


[program:FLASKAPP]
directory=/var/www/html/MYSITE/public_html/FLASKAPP/api
command=/var/www/html/MYSITE/public_html/FLASKAPP/venv/bin/gunicorn --workers 3 --bind unix:/var/www/html/MYSITE/public_html/FLASKAPP/api/FLASKAPP.sock FLASKAPP:app
autostart=true
autorestart=true
stderr_logfile=/var/log/FLASKAPP.err.log
stdout_logfile=/var/log/FLASKAPP.out.log

以及我的nginx站点启用文件:

^{pr2}$

我编写了一个函数来检查请求url

    @app.errorhandler(404)
    def page_not_found(error):
         return 'This route does not exist {}'.format(request.url), 404

返回:

此路由不存在http://MYSITE/FLASKAPP

Flask应用程序显然在工作,但路由被搞砸了。我该怎么解决这个问题?在


Tags: comlogtrue应用程序网站varhtmlwww