Apache httpd : Configure mod_wsgi2023/03/03 |
Install [mod_wsgi (WSGI : Web Server Gateway Interface)] to make Python scripts be fast.
|
|
[1] | |
[2] | Install [mod_wsgi]. |
[root@www ~]# dnf -y install python3-mod_wsgi
|
[3] | For example, For example, configure WSGI to be able to access to [/test_wsgi] from [/var/www/html/test_wsgi.py]. |
[root@www ~]#
vi /etc/httpd/conf.d/python3_wsgi.conf # create new
WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py
systemctl restart httpd |
[4] | Create a test script which you set above. |
[root@www ~]#
vi /var/www/html/test_wsgi.py # 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' \ '</html>\n'.encode("utf-8") response_header = [('Content-type','text/html')] start_response(status,response_header) return [html] |
[5] | To use Django, Configure like follows. ( for Django settings, refer to here ) For example, Configure [test_app] under the [/home/alma/testproject] which is owned by [alma] user. |
[root@www ~]#
vi /etc/httpd/conf.d/django.conf # create new WSGIDaemonProcess test_app python-path=/home/alma/testproject:/home/alma/django/lib/python3.9/site-packages WSGIProcessGroup test_app WSGIScriptAlias /django /home/alma/testproject/testproject/wsgi.py <Directory /home/alma/testproject> Require all granted </Directory>
[root@www ~]#
systemctl reload httpd # if SELinux is enabled and also use user directory like the example, it needs to change policy [root@www ~]# ll -d /home/alma drwx------. 6 alma alma 165 Mar 16 10:13 /home/alma[root@www ~]# chmod 711 /home/alma [root@www ~]# setsebool -P httpd_read_user_content on |
Sponsored Link |