FreeBSD 14
Sponsored Link

Apache httpd : Configure mod_wsgi2024/02/01


Install [mod_wsgi (WSGI : Web Server Gateway Interface)] to make Python scripts be fast.

[1] Install [mod_wsgi].
root@www:~ #
pkg install -y ap24-py39-mod_wsgi
[2] For example, For example, configure WSGI to be able to access to [/test_wsgi] from [/usr/local/www/apache24/data/].
root@www:~ #
vi /usr/local/etc/apache24/modules.d/270_mod_wsgi.conf
# uncomment

LoadModule wsgi_module libexec/apache24/
root@www:~ #
vi /usr/local/etc/apache24/Includes/wsgi.conf
# create new

WSGIScriptAlias /test_wsgi /usr/local/www/apache24/data/
root@www:~ #
service apache24 reload
[3] Create a test script which you set above.
root@www:~ #
vi /usr/local/www/apache24/data/
# create new

def application(environ, start_response):
    status = '200 OK'
    html = '<html>\n' \
           '<body>\n' \
           '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \
           'WSGI Test Page\n' \
           '</div>\n' \
           '</body>\n' \
    response_header = [('Content-type','text/html')]
    return [html]
[4] To use Django, Configure like follows. ( for Django settings, refer to here )
For example, Configure [test_app] under the [/home/freebsd/testproject] which is owned by [freebsd] user.
root@www:~ #
vi /usr/local/etc/apache24/Includes/django.conf
# create new

WSGIDaemonProcess testapp python-path=/home/freebsd/testproject:/home/freebsd/django/lib/python3.9/site-packages
WSGIProcessGroup testapp
WSGIScriptAlias /django /home/freebsd/testproject/testproject/

<Directory /home/freebsd/testproject>
    Require all granted

root@www:~ #
service apache24 reload
# if you use user directory like the example, it needs to change the directory permission

root@www:~ #
ls -ld /home/freebsd

drwx------ 5 freebsd freebsd 14 Feb 1 11:47 /home/freebsd
root@www:~ #
chmod 711 /home/freebsd

Matched Content