0

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:

enter image description here

Community
  • 1
  • 1
chrx
  • 2,169
  • 5
  • 24
  • 45
  • hmms ! You try using wsgi document as cgi ? am i right ? Check directory definition for `FallbackResource, DirectoryIndex,IfModule dir_module` and remove `initial startup proccess on flask`. Directory index your starting point, can define on main `apache2.conf`(But don't forget directory pattern, so not all, only your script directory). – dsgdfg Jul 25 '16 at 20:08
  • I'm afraid I don't fully understand what you mean: I just got the virtual host configuration from the linked article (and as I mention, everything works fine if I'm satisfied having the application respond to the URL `http://mywebsite.com`). – chrx Jul 26 '16 at 09:08

1 Answers1

1

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/

  • Thanks for your reply, but my problem is exactly how to configure the virtual server to map to `http://mywebsite.com/FlaskApp/` URL (since the solution I found in the mentioned thread doesn't seem to work). I'd prefer not to have to make changes to the flask application (which I took from the linked article example, and basically works as expected if I just directly map the apache virtual server to the main domain name mywebsite.com) – chrx Jul 26 '16 at 09:08
  • Apache Virtual server configuration uses a hostname to show a website or another, so you should use the domain only under virtual server config. The url rewrite you need (redirection to /FlaskApp) could be done by adding: Redirect "/" "/FlaskApp" – Tomás Gonzalez Dowling Jul 26 '16 at 13:15
  • I tried to add the `Redirect` but without success. In any case I finally solved using a subdomain `ServerName flaskapp.mywebsite.com`. – chrx Jul 26 '16 at 14:56
  • Create a conf `sub_domain.main_domain.com` add to site apache ! **Huh , can't publish two service on single port !** So read my comment, apache redirect using system resource 2 time. Use flask app as `CGI` or remove `APACHE` only use `FLASK`. `I love your worries` :) @chrx – dsgdfg Jul 27 '16 at 07:01