运行 Apache 下的 Flask 应用程序与 Plesk
Running a Flask App under Apache with Plesk
问题无穷无尽 运行使用 Plesk 在 Apache 下使用 Flask。真的一直在为这个问题挠头。
当我使用 Plesk 时,我意识到我需要使用 /var/www/vhosts 下的 vhosts 配置文件而不是虚拟主机配置(位于典型的 "sites-available" Apache 中的目录)。
当我尝试 运行 我的 Flask 应用程序时,我在 Apache 错误日志中收到错误:
Timeout when reading response headers from daemon process 'unifica': /apps/start.wsgi
我的 wsgi 应用程序文件在这里:
/apps/start.wsgi
全文如下:
activate_this = '/apps/unifica/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from unifica import app as application
如您所见。我正在使用虚拟环境。
随后,我的实际应用程序在这里:
apps/unifica/main.py
全文如下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host='0.0.0.0')
因为我的网站是通过 ssl 保护的;我有以下两个虚拟主机配置:
vhost.conf and vhost_ssl.conf
我的 vhost.conf 包含:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
(重定向不安全的请求)
我的 vhost_ssl.conf 包含:
WSGIDaemonProcess unifica user=flaskuser group=flaskgroup threads=5
WSGIScriptAlias / /apps/start.wsgi
<Directory /apps >
WSGIProcessGroup unifica
WSGIApplicationGroup %{GLOBAL}
Require all granted
WSGIScriptReloading On
</Directory>
flaskuser 存在并且属于 flaskgroup。我已将 0755 权限分配给 /apps/ 文件夹中的 flaskuser(作为所有者)。
知道我哪里出错了吗?我想我在某个地方犯了一个相当明显的错误...
如果您还没有解决这个问题,我可以通过在 CentOS7 上编辑 Plesk 12.5 中的自定义 vhost 文件来让 Flask 工作。它位于此处;
/var/www/vhosts/system/{域}/conf/vhost.conf
添加的示例;
<VirtualHost *:80>
ServerName example.com
ServerAdmin me@example.com
WSGIScriptAlias /var/www/vhost/{domain}/{subdomain}/flaskapp.wsgi
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/vhost/{domain}/{subdomain}/static
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
在我的设置中,我使用权限 705。请记住,其中一些编辑是针对子域进行的。希望您的问题得到解决!
问题无穷无尽 运行使用 Plesk 在 Apache 下使用 Flask。真的一直在为这个问题挠头。
当我使用 Plesk 时,我意识到我需要使用 /var/www/vhosts 下的 vhosts 配置文件而不是虚拟主机配置(位于典型的 "sites-available" Apache 中的目录)。
当我尝试 运行 我的 Flask 应用程序时,我在 Apache 错误日志中收到错误:
Timeout when reading response headers from daemon process 'unifica': /apps/start.wsgi
我的 wsgi 应用程序文件在这里:
/apps/start.wsgi
全文如下:
activate_this = '/apps/unifica/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from unifica import app as application
如您所见。我正在使用虚拟环境。 随后,我的实际应用程序在这里:
apps/unifica/main.py
全文如下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host='0.0.0.0')
因为我的网站是通过 ssl 保护的;我有以下两个虚拟主机配置:
vhost.conf and vhost_ssl.conf
我的 vhost.conf 包含:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
(重定向不安全的请求)
我的 vhost_ssl.conf 包含:
WSGIDaemonProcess unifica user=flaskuser group=flaskgroup threads=5
WSGIScriptAlias / /apps/start.wsgi
<Directory /apps >
WSGIProcessGroup unifica
WSGIApplicationGroup %{GLOBAL}
Require all granted
WSGIScriptReloading On
</Directory>
flaskuser 存在并且属于 flaskgroup。我已将 0755 权限分配给 /apps/ 文件夹中的 flaskuser(作为所有者)。
知道我哪里出错了吗?我想我在某个地方犯了一个相当明显的错误...
如果您还没有解决这个问题,我可以通过在 CentOS7 上编辑 Plesk 12.5 中的自定义 vhost 文件来让 Flask 工作。它位于此处;
/var/www/vhosts/system/{域}/conf/vhost.conf
添加的示例;
<VirtualHost *:80>
ServerName example.com
ServerAdmin me@example.com
WSGIScriptAlias /var/www/vhost/{domain}/{subdomain}/flaskapp.wsgi
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/vhost/{domain}/{subdomain}/static
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
在我的设置中,我使用权限 705。请记住,其中一些编辑是针对子域进行的。希望您的问题得到解决!