Problems with deploying Flask application on Apache 2.4

816 Views Asked by At

I'm trying to deplay my Flask application on a RHEL7 Apache 2.4 server. File structure is the following inside /var/www/html

/app
 app.wsgi
  /app
   app.py
   /templates
   /static

In my /etc/httpd/conf/httpd.conf I have the following code to set up my project:

    <VirtualHost *>
        ServerName 10.65.112.75:443
        WSGIDaemonProcess app user=apache group=apache threads=5 home=/var/www/html/app/app
        WSGIScriptAlias / /var/html/app/app.wsgi

<Directory /var/www/html/app/app/>
        WSGIProcessGroup app
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On
        Order deny,allow
        Require all granted
</Directory>
        Alias /static /var/www/html/app/app/static/
<Directory /var/www/html/app/app/static/>
        Order deny,allow
        Require all granted
</Directory>

And my app.wsgi contains the following:

#!/usr/bin/python
import sys
sys.path.insert(0, "/var/www/html/app/app/")
from app import app as application

The code for the project itself can be found in my github repository here.

I do not get any errors when trying to browse the server. It just doesnt do anything. Running my script from the terminal works, though.

Thanks for the help.

1

There are 1 best solutions below

4
On

There are various things which aren't right.

You have:

WSGIScriptAlias / /var/html/app/app.wsgi

whereas it appears it should be:

WSGIScriptAlias / /var/www/html/app/app.wsgi

And:

<Directory /var/www/html/app/app/>

appears it should be:

<Directory /var/www/html/app>

Your VirtualHost definition also looks wrong. You have:

<VirtualHost *>
    ServerName 10.65.112.75:443

If you really want this to be for HTTPS connections, you are missing all the SSL directives to add a SSL certificate.

ServerName would also usually be a fully qualified domain name and not an IP:PORT. The port number would usually be in the VirtualHost directive. For example, for HTTP, use:

<VirtualHost *:80>
    ServerName my.host.name

where my.host.name is the full public host name for your machine which you use in the URL, not an IP address.