0

NOTE: This question is different from 'Add a prefix to all Flask routes' as I am trying to resolve this at apache level. Additional, the suggested fix for flask routes did not work!

Following on from this post, I'm trying to set up apache to serve PHP files by default, but point a given alias (i.e. /flaskapp) to a wsgi path. The wsgi file in turn routes requests to a python flask app.

Here's the apache config that I'm trying (under 000-default.conf):

<VirtualHost *:80>
        ServerName localhost
        ServerAdmin webmaster@localhost

        Alias / /var/www/html/
        <Directory "/var/www/html">
            Order Deny,Allow
            Allow from all
            Require all granted
        </Directory>

        WSGIScriptAlias /flaskapp "/var/www/flaskapp/deploy.wsgi"
        <Directory /var/www/flaskapp>
                 Options +ExecCGI
                 Order allow,deny
                 Allow from all
        </Directory>
</VirtualHost>

After doing a service apache2 restart I find that requests to http://myip/flaskapp result in a 404 error. Everything else works fine.

Things I've tried so far:

  • Double checking all the file and folder paths (no issues found)
  • Using the wsgi part of the above code to set up the wsgi app as a standalone virtualhost (works fine)
  • Adding app.config['APPLICATION_ROOT'] = '/flaskapp' to my app.py file, as suggested the question 'Add a prefix to all Flask routes' (Didn't have any effect)

Where could I be going wrong?

Community
  • 1
  • 1
user2761030
  • 1,385
  • 2
  • 20
  • 33
  • 1
    Don't use Alias /. That overrides mod_wsgi completely. Use DocumentRoot directive to specify where primary site files are located. That way mod_wsgi can override for a sub URL. – Graham Dumpleton Jul 30 '16 at 02:39
  • And yes you are correct, not same question as claimed duplicate. People here on SO usually don't understand subtleties though and just make assumptions. – Graham Dumpleton Jul 30 '16 at 02:41
  • Thanks @GrahamDumpleton - adding DocumentRoot resolved the issue. Feel free to write this up as an answer, or I can do so this evening... – user2761030 Jul 30 '16 at 11:54

1 Answers1

1

Instead of:

    Alias / /var/www/html/
    <Directory "/var/www/html">
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>

use:

    DocumentRoot /var/www/html/
    <Directory "/var/www/html">
        Order Deny,Allow
        Allow from all
        Require all granted
    </Directory>

Using '/' with Alias takes precedence over everything else including mod_wsgi's ability to intercept requests at a sub URL. So for stuff at root of the site you need to use DocumentRoot directive.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134