Categories: python, apache, flask, wsgi

404 when trying to deploy Flask app to Apache

1 answer

I am trying to deploy a Flask app to my Linux based server with no success. I have already looked through different approaches and entries on stackoverflow, but nothing seems to work. To test it a little cleaner, I have created a simple test application that I am trying to run locally:

In /var/www/test:

from flask import Flask  app = Flask(__name__)  @app.route('/') def index ():         return "Hello World!"  if __name__ == '__main__': 


from test import app as application 

and an empty file.

In /etc/apache2/sites-available:


<VirtualHost *>     ServerName *Local IP address*      WSGIDaemonProcess test user=www-data group=www-data threads=5     WSGIScriptAlias / /var/www/test/test.wsgi      <Directory /var/www/test>         WSGIProcessGroup test         WSGIApplicationGroup %{GLOBAL}         Require all granted     </Directory> </VirtualHost> 

The test.conf file was registered via a2ensite test.conf and libapache2-mod-wsgi was installed via apt on my local Debian Buster distribution I am testing this on (localhost). Python2 and 3 are installed together with Flask for each of them. Every file and the test folder are owned by www-data with the group www-data. And of course I am restarting the application after every change with service apache2 restart.

I can successfully run the application with python on localhost:5000, printing "Hello World!".

I don't see anything suspicious in the Apache error-log either, just:

[Sun Oct 27 22:16:55.923721 2019] [mpm_event:notice] [pid 26336:tid 140548964586624] AH00489: Apache/2.4.38 (Debian) mod_wsgi/4.6.5 Python/2.7 configured -- resuming normal operations [Sun Oct 27 22:16:55.923771 2019] [core:notice] [pid 26336:tid 140548964586624] AH00094: Command line: '/usr/sbin/apache2' 

What am I missing? Why am I getting a 404? Is there any way to see, if the application is even running or just attempting to run?

All answers to this question, which has the identifier 58583488

The best answer:

ServerName *Local IP address* <- this. You can't use an IP there, it has to be a hostname (that matches the one you use in the URL you access). If you use an IP to access your server, it will default to the first defined vhost, as it won't match any of the Servernames, which is probably not the one you just defined.

So either put a hostname there and define it in your hosts file if it's a name that doesn't resolve, or edit the default vhost (vhosts are loaded in alphanumerical order, which mean unless test.conf is the first entry when listing sites-available, it is not the first one and will not be used when accessing the server with an IP).

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data