如何在apache2上以wsgi的身份将Flask App部署到现有的VirtualHost中? [英] How to deploy Flask App into existing VirtualHost as wsgi on apache2?
问题描述
我正在努力将Flask应用程序部署到现有的VirtualHost配置中.我想将所有Web应用程序都保留在同一端口的同一域下.遵循大多数教程时,它可以正常工作:
I'm struggling on deploying a Flask app into an existing VirtualHost configuration. I'd like to keep all web applications under the same domain on the same port. When following the majority of tutorials it work's without problems:
<IfModule mod_ssl.c>
<VirtualHost *:81>
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
SSLProxyEngine On
ServerName localhost
WSGIScriptAlias /flasktest /var/www/SetImageText/SetImageText.wsgi
<Directory /var/www/SetImageText/SetImageText/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/SetImageText/SetImageText/static
<Directory /var/www/SetImageText/SetImageText/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/own_domain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/own_domain/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/own_domain/fullchain.pem
但是当我尝试将其集成到现有配置中时:
But when I try to integrate this into existing config:
<IfModule mod_ssl.c>
<VirtualHost own_domain:443>
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
SSLProxyEngine On
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
DocumentRoot /var/www
<Directory /var/www>
Order allow,deny
deny from all
</Directory>
WSGIScriptAlias /flasktest /var/www/SetImageText/SetImageText.wsgi
<Directory /var/www/SetImageText/SetImageText/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/SetImageText/SetImageText/static
<Directory /var/www/SetImageText/SetImageText/static/>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/owncloud>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
Order allow,deny
allow from all
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/own_domain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/own_domain/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/own_domain/fullchain.pem
只能用404回答.有人知道将这些wsgi内容集成到现有Virtualhost中的可能性吗?
It will only answer with 404. Does someone know a possibility to integrate this wsgi stuff into an existing Virtualhost?
推荐答案
我的虚拟主机文件没有您的复杂,但是我可以通过以下操作使Flask应用程序正常运行(将WSGIScriptAlias集成到我现有的虚拟主机文件中)来自mod_wsgi文档的示例.
My virtual host file isn't as complex as yours but I was able to get my Flask app working (integrating WSGIScriptAlias into my existing virtual host file) by following the example from the mod_wsgi docs.
http://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
特别是安装WSGI应用程序"部分中的示例虚拟主机配置.
Specifically the sample virtual host configuration in the section "Mounting the WSGI Application".
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster@example.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这篇关于如何在apache2上以wsgi的身份将Flask App部署到现有的VirtualHost中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!