flask - 使用 Apache2 在网站的非根 url 上的烧瓶应用程序
问题描述
我有一个 Flask 应用程序,我想将它托管在我们实验室网站的子域/非根 url 上。例如,我希望 mylab.com/portal 指向烧瓶应用程序。我遵循了许多指南,但我不断收到 404 错误。
我的目录结构:
/var/www/
-html/
-Stuff for mylab.com
-FlaskApp/
-FlaskApp.wsgi
-FlaskApp/
-__init__.py
-static/
-templates/
-...
FlaskApp.wsgi:
#!/usr/bin/python3
activate_this = '/home/cogsci-cnddcollab/FlaskApp/venv/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/FlaskApp')
from FlaskApp import app as application
/etc/apache2/sites-available/000-default.conf
WSGIRestrictStdout Off
WSGIScriptReloading On
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName mylab.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
Redirect permanent / https://mylab.com/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
<Directory "/var/www/html">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
## FlaskApp
WSGIDaemonProcess FlaskApp_wsgi user=cogsci-cnddcollab group="domain users" threads=5
WSGIScriptAlias /portal /var/www/FlaskApp/FlaskApp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
WSGIProcessGroup FlaskApp_wsgi
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Alias /portal/static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static>
Require all granted
</Directory>
Alias /portal/templates /var/www/FlaskApp/FlaskApp/templates
<Directory /var/www/FlaskApp/FlaskApp/templates>
Require all granted
</Directory>
</VirtualHost>
现在,当我重新启动 apache2 服务并访问 mylab.com/portal 时,我遇到了 404 错误。我已添加APPLICATION_ROOT=/portal
到我的 config.py 文件中。
任何帮助将不胜感激。
解决方案
推荐阅读
- powershell - 在客户端文件夹中组织文件
- reactjs - react-bootstrap reactjs覆盖弹出框仅在悬停时触发
- python - 如何在 wxPython 向导中单独修改面板?
- amazon-ec2 - 使用私钥在 AWS EC2 实例上提供 SSH 访问
- command-line - 命令行; 删除以特定字符开头的文件夹中的静态文件
- server - GraphQL Clojure:获取 GQL 查询字段
- java - 在两个主要类之间传递字符串变量,将其传递给字符串数组
- javascript - 用嵌套数据续集 findAll 限制
- python - 将 pandas shift() 应用于时间索引时间序列时出现问题
- vega - 如何使用 Vega 加载特定的 Topojson