我有以下配置文件:
/etc/apache2/sites-available/propman.domain.com.conf:
WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess propman_proc python-home=/var/www/propman/.venv processes=1 threads=1
WSGIProcessGroup propman_proc
<VirtualHost *:80>
Include /etc/apache2/sites-available/propman.domain.com.common
</VirtualHost>
<VirtualHost *:443>
Include /etc/apache2/sites-available/propman.domain.com.common
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
</VirtualHost>
/etc/apache2/sites-available/propman.domain.common:
LogLevel debug
ServerName propman.domain.com
ServerAlias www.propman.domain.com
DocumentRoot /var/www/propman
WSGIScriptAlias /propman /var/www/propman/test1.wsgi
ErrorLog ${APACHE_LOG_DIR}/propman_error.log
CustomLog ${APACHE_LOG_DIR}/propman_access.log combined
和脚本:
/var/www/propman/test1.py:
from flask import Flask
app = Flask(__name__)
@app.route("/propman")
def hello():
return "Hello world again!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, debug=True)
/var/www/propman/test1.wsgi:
import logging
import sys
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/propman/')
from test1 import app as application
我的问题是,当我访问 http://propman.domain.com 时,我看到的是 index.html 文件而不是端点的结果。
如果我关闭 apache 并在端口 80 上的虚拟环境中运行脚本并访问 domain.com/propman,它会在浏览器中按预期工作(我再次看到 Hello world!)。 我在 propman_error 日志中没有看到任何警告或错误
我相信问题出在 apache2 配置文件中。我尝试过
的变体WSGIScriptAlias /propman /var/www/propman/test1.wsgi
WSGIScriptAlias / /var/www/propman/test1.wsgi
和
@app.route("/propman")
@app.route("/")
我的 apache_error 日志现在是干净的,但当我访问 http://propman.domain.com
时,我仍然是 index.html 的内容我发现flask没有安装在venv中:pipenv installflask。 您确实需要检查所有错误日志,而不仅仅是站点的错误日志!