Apache webserver and Flask app Apache webserver and Flask app apache apache

Apache webserver and Flask app


After little bit for googling I got it resolved.

The Apache 2.4 and above have additional security enabled, where the syntax has changed:

In Apache 2.2 if we want to allow a folder to be accessed, e.g. the site files, then we give below options:

  <Directory /path/to/site/files>    Order deny,allow    Allow from all  </Directory>

But in case of Apache 2.4 we need to give below option:

<Directory /path/to/site/files>        Options Indexes FollowSymLinks        AllowOverride None        Require all granted</Directory>

This allowed me the access and 403 forbidden error was resolved and also mod_wsgi helped me to create a flask app, which I can access via http://localhost and not http://localhost:5000


To start flask on port 80 requires root privileges, but it wouldn't work for you in this case either because Apache is already running on that port, and you can't (generally) have two unrelated processes listening on the same port.

I am assuming you want to do this for general testing/development and one way to do this is to make use of a reverse http proxy which lets you not having to worry about restarting apache all the time when code is changed.

I recommend starting the app on a specific port that is not 5000; try 8000

app.run(host='0.0.0.0', port=8000)

In your default site configuration (it should be /etc/apache2/sites-available/default) you can edit that to include this:

    <Location />        ProxyPass http://localhost:8000        ProxyPassReverse  http://localhost:8000    </Location>

This will take over the root of your default site. If this is not desirable you want to define a separate virtualhost (ideally in a separate file) and then call a2ensite <filename>. Also for the above configuration to function, you will also need to call a2enmod proxy_http. Both those command require root privileges.

For production usage you probably want to use something like mod_wsgi, you can check the list of related questions on the sidebar to help you get started.