首页 > 解决方案 > Apache2 上的第二个 Flask 应用程序出现问题

问题描述

我有两个域,指向同一个(apache2)服务器。我使用两个相等的虚拟主机文件将请求路由到所需的目录。在这两个目录中,我都有完全相同的 WSGI 脚本(当然路径除外)。但是,对于第一个目录,flask 已启动并正在运行,但对于第二个目录,我只看到所需文件夹的索引概述,但 flask 没有运行。有谁知道什么可能导致这个问题?

这是虚拟主机配置:

<VirtualHost www.domain1.de:80>
    ServerName www.domain1.de
    ServerAlias domain2.de *.domain2.de
    ServerAdmin admin@domain1.de
    WSGIScriptAlias / /var/www/html/domain1/domain1.wsgi
    <Directory /var/www/html/domain1/>
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

<VirtualHost www.domain2.de/:80>
    ServerName www.domain2.de
    ServerAlias domain2.de *.domain2.de
    ServerAdmin admin@domain2.de
    WSGIScriptAlias / /var/www/html/domain2/domain2.wsgi
    <Directory /var/www/html/domain2/>
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>

以下是标准烧瓶剪断:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'


if __name__ == "__main__":
    app.debug=True
    app.run()

这是 WSGI 文件。这两个应用程序都一样,我当然相应地更改了路径:

import sys
sys.path.insert(0, '/var/www/html/domain1')
from init import app as application

标签: pythonflaskapache2

解决方案


对于面临同样问题的每个人,我使用以下虚拟主机配置解决了它:

<VirtualHost www.domain1.de:80>
        ServerAdmin admin@admin.de
        DocumentRoot /var/www/html/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        WSGIDaemonProcess domain1 user=youruser group=yourgroup threads=5
        WSGIScriptAlias /domain1 /var/www/html/domain1/domain1.wsgi
        <Directory /var/www/html/domain1>
        WSGIApplicationGroup domain1
        WSGIProcessGroup domain1
        Order deny,allow
        Allow from all
        </Directory>

        WSGIDaemonProcess domain2 user=youruser group=yourgroup threads=5
        WSGIScriptAlias /domain2 /var/www/html/domain2/domain2.wsgi
        <Directory /var/www/html/domain2>
        WSGIApplicationGroup domain2
        WSGIProcessGroup domain2 
        Order deny,allow
        Allow from all
        </Directory>
</VirtualHost>

事实证明,我错过了守护进程:

WSGIDaemonProcess domain1 user=youruser group=yourgroup threads=5

Graham Dumpelton的博客帮助很大:


推荐阅读