Apache2上的第二个Flask应用程序出现问题

时间:2019-03-01 16:22:14

标签: python flask apache2

我有两个域,指向同一台(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

1 个答案:

答案 0 :(得分:0)

对于面临相同问题的每个人,我都通过以下虚拟主机配置解决了该问题:

<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的博客是一个很大的帮助: