Skip to content

Instantly share code, notes, and snippets.

@filipemansano
Last active July 8, 2023 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipemansano/eaf8992eef757d89d7b2e9653f77bfc2 to your computer and use it in GitHub Desktop.
Save filipemansano/eaf8992eef757d89d7b2e9653f77bfc2 to your computer and use it in GitHub Desktop.
configure flask with apache + vhost
#####################################
install module wsgi on apache2 (https://pypi.org/project/mod-wsgi/)
####################################
(Install apache develop package)
apt-get install apache2-dev
(install mod_wsgi)
python3 -m pip install mod_wsgi
(execute command and copy content)
mod_wsgi-express module-config
(create a file "wsgi.load" and copy content of command above)
nano /etc/apache2/mods-available/wsgi.load
(enable module)
a2enmod wsgi
systemctl restart apache2
#####################################
create a virtual host with wsgi app
####################################
create a file 'app.wsgi' with content
nano app.wsgi
```
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from FlaskApp.app import app as application
```
-------------------------------------------------------------------------------------------------------
Note that I stored this file on a separate folder.
Storing the wsgi file on the same folder as you Flask app works as well, but is not recommended.
-------------------------------------------------------------------------------------------------------
(create a conf file 'yourdomain.conf' in folder '/etc/apache2/sites-available/')
<VirtualHost *:80>
ServerName xxxx.xxx
SetEnv APP_ENV dev
WSGIScriptAlias / /var/www/xxxxxxxxxxx/app.wsgi
<Directory /var/www/xxxxxxxxx/api/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
enable site with command
a2ensite yourdomain.conf
systemctl reload apache2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment