You are not logged in.

#1 2020-03-14 03:41:05

eric.meehan
Member
Registered: 2020-01-01
Posts: 52

Apache, WSGI, and Flask

Hello fellow people.

I am trying to run an Apache server from my Arch Linux station that will serve a flask application with Python.  I am having some problems getting the server to run, and I think there are some problems on the wiki.

According to the the wiki, I need to:
https://wiki.archlinux.org/index.php/Ap … r/mod_wsgi

1) Edit /etc/httpd/conf/httpd.conf to include:

LoadModule wsgi_module modules/mod_wsgi.so

This works fine.  I restart apache using

 sudo systemctl restart httpd

and the service is running as expected.

2) Add this line below the first:

WSGIScriptAlias /wsgi_app /srv/http/wsgi_app.py

and create the test file:

#-*- coding: utf-8 -*-
def wsgi_app(environ, start_response):
    import sys
    output = sys.version.encode('utf8')
    status = '200 OK'
    headers = [('Content-type', 'text/plain'),
               ('Content-Length', str(len(output)))]
    start_response(status, headers)
    yield output

# mod_wsgi need the *application* variable to serve our small app
application = wsgi_app

This causes the error message:

* httpd.service - Apache Web Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Fri 2020-03-13 22:28:12 UTC; 4s ago
    Process: 253806 ExecStart=/usr/bin/httpd -k start -DFOREGROUND (code=exited, status=1/FAILURE)
   Main PID: 253806 (code=exited, status=1/FAILURE)

Mar 13 22:28:12 Hangar-Bay systemd[1]: Started Apache Web Server.
Mar 13 22:28:12 Hangar-Bay httpd[253806]: AH00526: Syntax error on line 544 of /etc/httpd/conf/httpd.conf:
Mar 13 22:28:12 Hangar-Bay httpd[253806]: Invalid option to WSGI script alias definition.
Mar 13 22:28:12 Hangar-Bay systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
Mar 13 22:28:12 Hangar-Bay systemd[1]: httpd.service: Failed with result 'exit-code'.

The wiki seems to be differing significantly from the Flask documentation here.  First of all, the test file makes no sense.  According to flask, the file should be a .wsgi file with the format:

activate_this = '/path/to/env/bin/activate_this.py'
with open(activate_this) as file_:
    exec(file_.read(), dict(__file__=activate_this))

from yourapplication import app as application

And the line in the config file should be something like this:

WSGIScriptAlias /wsgi_app /srv/http/wsgi_app.wsgi

To be clear, the first argument to the WSGIScriptAlias is like a route name - you would type http://url.com/wsgi_app in this example.  The second part should point to the .wsgi file that the wsgi application should load.

Even when I try this, though, I get exactly the same output after I restart apache:

* httpd.service - Apache Web Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Fri 2020-03-13 22:38:16 UTC; 3s ago
    Process: 253852 ExecStart=/usr/bin/httpd -k start -DFOREGROUND (code=exited, status=1/FAILURE)
   Main PID: 253852 (code=exited, status=1/FAILURE)

Mar 13 22:38:16 Hangar-Bay systemd[1]: Started Apache Web Server.
Mar 13 22:38:16 Hangar-Bay httpd[253852]: AH00526: Syntax error on line 544 of /etc/httpd/conf/httpd.conf:
Mar 13 22:38:16 Hangar-Bay httpd[253852]: Invalid option to WSGI script alias definition.
Mar 13 22:38:16 Hangar-Bay systemd[1]: httpd.service: Main process exited, code=exited, status=1/FAILURE
Mar 13 22:38:16 Hangar-Bay systemd[1]: httpd.service: Failed with result 'exit-code'.

It seems the problem is in the last line.  Specifically, the last argument of the last line that points to the .wsgi file.  I have no idea how to proceed at this point, as I have exhausted the relevant pages on google.  Any help would be appreciated!

Offline

#2 2020-03-24 01:57:54

eric.meehan
Member
Registered: 2020-01-01
Posts: 52

Re: Apache, WSGI, and Flask

Has anyone set up a python server using flask and apache on Arch?

Offline

Board footer

Powered by FluxBB