1 - Go in the DNS settings for your domain
2 - Create a new A entry with hostname = [subdomain] and IP = [server_ip]
3 - Install and enable mod_wsgi for aoache on your server:
sudo apt-get install libapache2-mod-wsgi python-dev
sudo a2enmod wsgi
4 - Create a app.wsgi for your flask project in the folder below your app.py
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/[path_to_flask_project/")
from FlaskApp import app as application
application.secret_key = '[your_secret_key]'
5 - Create a new Apache's virtualhost site on etc/apache2/site-availables/[subdomain].[domain].conf
6 - Paste in the file the following code
<VirtualHost *:80>
ServerName [subdomain].[domain]
ServerAdmin admin@m[domain]
WSGIScriptAlias / /var/www/[path_to_flask_project]/app.wsgi
WSGIDaemonProcess [your_app] python-home=/var/www/html/[path_to_flask_app]/venv
<Directory /var/www/[path_to_flask_app]/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/[path_to_flask_app]/static
<Directory /var/www/[path_to_flask_app]/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
6 - Enable the webiste and reload apache
sudo a2ensite api.giuseppegullo.com
sudo service apache2 reload
7 - For any problem check Apache's log on /var/log/apache2/ with
tail -f error.log