7

Installing Apache mod_wsgi in Arch Linux

 3 years ago
source link: https://www.devdungeon.com/content/installing-apache-modwsgi-arch-linux
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Installing Apache mod_wsgi in Arch Linux

Submitted by NanoDano on Sun, 04/26/2015 - 13:59

This covers how to install and start using mod_wsgi with Apache on Arch Linux.

Install WSGI for Apache

sudo pacman -S mod_wsgi

For more details refer to Arch Linux Wiki page on mod_wsgi.

Add the module to Apache's config file /etc/httpd/conf/httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so

Tell Apache when and where to use WSGI

Apache will only run WSGI when you tell it to. By adding a WSGIScriptAlias in the Apache host entry, Apache will know to when to invoke WSGI. You can create your own Python file, but it has to follow a few rules to return data correctly. Applications like Django create a wsgi.py file for you, and you just need to point Apache at that file.

,

This script alias line will alias the URL /myapp to the index.py file.

WSGIScriptAlias /myapp /srv/http/index.py

Example Apache VirtualHost entry

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/srv/http/devdungeon.com.com"
    ServerName devdungeon.com.com
    ServerAlias www.devdungeon.com.com
    ErrorLog "/var/log/httpd/devdungeon.com-error_log"
    CustomLog "/var/log/httpd/devdungeon.com-access_log" common
    WSGIScriptAlias / /srv/http/devdungeon.com/index.py
</VirtualHost>

Example index.py file

def wsgi_app(environ, start_response):
    output = "<html><body><h1>WSGI working!</ht></body></html>\n".encode('utf-8')
    status = '200 OK'
    headers = [('Content-type', 'text/html'),
               ('Content-Length', str(len(output)))]
    start_response(status, headers)
    yield output


# mod_wsgi needs the "application" variable to serve our small app
application = wsgi_app

Advertisement


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK