Apache httpd : Configure mod_wsgi2022/03/16 |
|
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/cent/testproject] which is owned by [cent] user. |
|
[root@www ~]#
vi /etc/httpd/conf.d/django.conf # create new
WSGIDaemonProcess test_app python-path=/home/cent/testproject:/home/cent/django/lib/python3.9/site-packages
WSGIProcessGroup test_app
WSGIScriptAlias /django /home/cent/testproject/testproject/wsgi.py
<Directory /home/cent/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/cent drwx------. 6 cent cent 165 Mar 16 10:13 /home/cent[root@www ~]# chmod 711 /home/cent [root@www ~]# setsebool -P httpd_read_user_content on |
|
| Sponsored Link |
|
|