0

I'm trying to deploy my flask application on Apache web server using mod_wsgi. After the deployment, when i go to the 'healthCheck' URL i configured to return a simple text message, the app is not responding and it's timing out.

This is my wsgi file:

<VirtualHost *:5000>
        ServerName <My ip address here>
        ServerAdmin admin@mywebsite.com
        WSGIScriptAlias / /var/www/ReleaseServices/ReleaseServices.wsgi
        <Directory /var/www/ReleaseServices/ReleaseServices/>
            Order allow,deny
            Allow from all
        </Directory>
        Alias /static /var/www/ReleaseServices/ReleaseServices/static
        <Directory /var/www/ReleaseServices/ReleaseServices/static/>
            Order allow,deny
            Allow from all
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I don't see any error in the apache logs as well. What could be the issue? Please ask me if any extra details are required.

  • maybe my answer (more elaborated) on other similar question (deploying `Flask` on `Apache` with `mod_wsgi`) can help you : https://stackoverflow.com/a/62512179/12368419 – cizario Jun 28 '20 at 10:01
  • @cizario My deployment is on unix and the issue is quite different: when i try to ping the healthcheck URL, it just keeps loading for ever and the app doesn't respond. I also don't see any errors in the apache logs. Let me know if you need any details. – user2769039 Jun 28 '20 at 12:51
  • refer to https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/#configuring-apache i guess you are missing some `Apache` rules – cizario Jun 28 '20 at 12:56
  • @cizario I believe i have everything that's required. Can you mention what you think is missing? – user2769039 Jun 28 '20 at 13:56
  • you are serving your app with `apache` on `unix` serevr so based on your `virtualhost conf` file above (and `wsgi` file) you are missing `WSGIDaemonProcess yourapplication user=user1 group=group1 threads=5`, and `WSGIProcessGroup yourapplication WSGIApplicationGroup %{GLOBAL}` read more on the doc – cizario Jun 28 '20 at 14:02
  • @cizario I followed this guide: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps : It doesn't mention those configs you said above. – user2769039 Jun 28 '20 at 14:08
  • ok, let's proceed step by step, #1 check if `httpd` is up and running `sudo service apache2 status ` #2 if not ok it could be (among other options) a wrong vhost conf (not necessarly yours, an other one) try `sudo apachectl configtest ` and then we see .. – cizario Jun 28 '20 at 14:19
  • @cizario: Yes, it is up and running. – user2769039 Jun 28 '20 at 14:25
  • i've read the tutorial (i assume you followed it step by step) and it seems there's nothing wrong, may be you need to restart apache to enforce it reloading all vhost conf including yours `sudo service apache2 restart` and don't forget to check `ReleaseServices` folder permissions and don't forget add the `5000` port to the firewall or replace it with the default `80` in your vhost conf (above) – cizario Jun 28 '20 at 14:37

1 Answers1

0

So i found the solution after searching a lot.

I was using scikit-learn in my init.py script and the import statement was causing issues and making the app unresponsive. After removing the import, it was working fine.

When i searched for solutions, i found some interesting facts related to the WSGI configuration, one of which i had missed out:

http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/

In that link, check the comment by Graham Dumpleton:

The specific solution is forcing use of the main interpreter by setting the application group to %{GLOBAL}. It is documented in http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API

Basically you have to add the following line to your .wsgi file:

WSGIApplicationGroup %{GLOBAL}

This will force a specific WSGI application to be run within the very first Python sub interpreter created when Python is initialised and hence solves the problem!