Приложение Flask по некорневому URL сайта с Apache2 - PullRequest
0 голосов
/ 07 июня 2018

У меня есть приложение 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.

Любая помощь будет принята с благодарностью.

...