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:
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.