繁体   English   中英

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

[英]Problem with second Flask Apps on 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

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

<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的博客提供了很大帮助:

暂无
暂无

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

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