Having no end of problems running Flask under Apache using Plesk. Really been scratching my head with this one.
As I am using Plesk, I realise that I need to use the vhosts conf files under /var/www/vhosts instead of the virtualhost config (sitting under the typical "sites-available" directory in Apache).
When I attempt to run my Flask App, I receive the error within my Apache error log:
Timeout when reading response headers from daemon process 'unifica': /apps/start.wsgi
My wsgi application file lives here:
/apps/start.wsgi
and reads as follows:
activate_this = '/apps/unifica/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from unifica import app as application
As you will notice. I am using a Virtual Environment. Subsequently, my actual application lives here:
apps/unifica/main.py
and reads as follows:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host='0.0.0.0')
As my site is secured over ssl; I have the following two vhost configurations:
vhost.conf and vhost_ssl.conf
My vhost.conf contains:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
(to redirect insecure requests)
My vhost_ssl.conf contains:
WSGIDaemonProcess unifica user=flaskuser group=flaskgroup threads=5
WSGIScriptAlias / /apps/start.wsgi
<Directory /apps >
WSGIProcessGroup unifica
WSGIApplicationGroup %{GLOBAL}
Require all granted
WSGIScriptReloading On
</Directory>
flaskuser exists and belongs to flaskgroup. I have assigned 0755 rights to flaskuser (as the owner) on the /apps/ folder.
Any idea where I am going wrong here? I presume I have made a fairly obvious mistake somewhere...
If you have not resolved this yet I was able to get Flask working by editing the custom vhost file in Plesk 12.5 this is on CentOS7. It's located here;
/var/www/vhosts/system/{domain}/conf/vhost.conf
Example of what was added;
<VirtualHost *:80>
ServerName example.com
ServerAdmin [email protected]
WSGIScriptAlias /var/www/vhost/{domain}/{subdomain}/flaskapp.wsgi
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/vhost/{domain}/{subdomain}/static
<Directory /var/www/vhost/{domain}/{subdomain}/static>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
On my setup I am using permissions 705. Keep in mind some of these edits are made for a subdomain. I hope you get your issue resolved!