简体   繁体   中英

deploy flask application on ubuntu/apache2: virtual host configuration

I'm trying to deploy a python/flask application on an apache2 installation on ubuntu (14.04), following the instructions at the link

The application seems to work and if I point the browser to http://mywebsite.com/ I correctly see the message returned by the Flask application.

My problem is, what if I want to install a second site as a different virtual host on the same machine (say a non-python application)? What I would like is that the virtual host is mapped to an URL like http://mywebsite.com/FlaskApp , while having the possibility to define another virtual host at http://mywebsite.com/MyOtherWebApp

This is the FlaskApp.conf file as per instructions on the mentioned article:

<VirtualHost *:80>
            ServerName mywebsite.com
            ServerAdmin admin@mywebsite.com
            WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
            <Directory /var/www/FlaskApp/FlaskApp/>
                    Order allow,deny
                    Allow from all
            </Directory>
            Alias /static /var/www/FlaskApp/FlaskApp/static
            <Directory /var/www/FlaskApp/FlaskApp/static/>
                    Order allow,deny
                    Allow from all
            </Directory>
            ErrorLog ${APACHE_LOG_DIR}/error.log
            LogLevel warn
            CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

and here is how the /var/www folder is structured after I installed the python app

/var/www
    +-- FlaskApp
    ¦   +-- FlaskApp
    ¦   ¦   +-- flaskenv
    ¦   ¦   +-- __init__.py
    ¦   ¦   +-- __init__.pyc
    ¦   ¦   +-- static
    ¦   ¦   +-- templates
    ¦   +-- flaskapp.wsgi
    ¦
    +-- MyOtherWebApp
        +-- ...

Some notes with more details:

  1. I don't have the possibility to use different domain names or diffent ports for the different VirtualHost
  2. I found this thread suggesting to use the directive ServerAlias as shown below to solve a similar problem, but if I do this and go to http://mywebsite.com/ I see a directory listing of the FlaskApp folder instead of the results of the flask service invocation, as in the screenshot below:

here the changed FlaskApp.conf:

<VirtualHost *:80>
    ServerName mywebsite.com/FlaskApp
    ServerAlias mywebsite.com/FlaskApp
    .
    .
    .

screenshot:

在此处输入图片说明

I think you missed that url in your controller. Perhaps you can add a index.html in FlaskApp folder to redirect to the correct url (or the other way around, if you leave ServerName mywebsite.com/FlaskApp, put an index file to redirect to FlaskApp). If index.html "hack" doesn't suit your needs, you may add another virtualserver to redirect from / to /FlaskApp/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM