Open shivprasadmj opened 5 months ago
It is possibly because you are not forcing the use of the main Python interpreter context by using WSGIApplicationGroup %{GLOBAL}
directive or application-group=%{GLOBAL}
option to WSGIScriptAlias
.
Various third party Python packages will not work in Python sub interpreters. This includes very popular packages such as numpy
and any thing that uses it.
There is additional details as to why in:
In short though, your application code could be deadlocking due to the problems with those third party packages and so the request never returns.
You also seem to be missing the correct directives to have your application run in daemon mode as well.
Can you ensure that you provide a more complete copy of the mod_wsgi configuration you are using so I can review it?
At least try with:
WSGIDaemonProcess your_application_name python-home=/var/www/html/flaskapps/myapp/venv python-path=/var/www/html/flaskapps/myapp
WSGIScriptAlias / /var/www/html/flaskapps/myapp/myapp.wsgi process-group=your_application_name application-group="%{GLOBAL}"
Thank you very much for your suggestion.
I've already implemented the configuration as you recommended.
Below are the detailed .conf file configurations I'm currently using:
<VirtualHost *:80>
ServerName domainname
# Redirect all HTTP traffic to HTTPS
Redirect permanent / https://domainname/
</VirtualHost>
<VirtualHost *:443>
ServerName domainname
SSLEngine on
SSLCertificateFile /var/www/html/flaskapps/ssl/domainname.crt
SSLCertificateKeyFile /var/www/html/flaskapps/ssl/domainname.key
SSLCACertificateFile /var/www/html/flaskapps/ssl/domainname.ca-bundle
WSGIProcessGroup dashboard
WSGIScriptAlias / /var/www/html/flaskapps/myapp/myapp.wsgi
WSGIDaemonProcess dashboard python-home=/var/www/html/flaskapps/myapp/venv python-path=/var/www/html/flaskapps/myapp/:/var/www/html/flaskapps/myapp/venv/lib/python3.9/site-packages/ threads=15 processes=3 user=apache group=apache
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/html/flaskapps/myapp >
Require all granted
</Directory>
ErrorLog /var/www/html/flaskapps/log/myapp_error.log
CustomLog /var/www/html/flaskapps/log/myapp_access.log combined
</VirtualHost>
Could you please let me know if you see any issues with these configurations?
Thank you.
You should not need to add /var/www/html/flaskapps/myapp/venv/lib/python3.9/site-packages/
to python-path
, that is what python-home
does when you give it the root of the virtual environment. The Flask docs has been wrong in some places in saying you need to add site-packages
directory to the path.
Add:
WSGIRestrictedEmbedded On
outside of all VirtualHost
sections if only using daemon mode.
Hi everyone,
I'm currently trying to deploy a Flask application on an Apache/2.4.6 server running on CentOS, and I've encountered a problem. Despite following all the necessary steps for deployment, whenever I try to access the app through its URL, I receive an error message stating: "Script timed out before returning headers: myapp.wsgi".
Here's a brief overview of my setup:
Virtual Environment Location: My Python virtual environment is located at /var/www/html/flaskapps/myapp/venv.
Apache Configuration: In my Apache .conf file, I've set up the following directives:
WSGI File Content: In my myapp.wsgi file, I've included the Python path to my application and the site-packages directory inside the virtual environment. Additionally, I've attempted to activate the virtual environment by executing the activate_this.py script. Here is the content of myapp.wsgi:
I have double-checked all the paths specified in the .conf file, and they appear to be correct. However, I'm still facing the timeout issue when trying to access the application.
Also, I went through the documentation: https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html to find out the solution for the issue.
Has anyone faced a similar issue or have any suggestions on what might be going wrong? Any advice or guidance would be greatly appreciated.
Thank you!