mod_wsgi (WSGI : Web Server Gateway Interface) をインストールして、Python スクリプトの実行を高速化します。
[root@localhost ~]# yum -y install mod_wsgi |
[root@localhost ~]# vi /etc/httpd/conf.d/wsgi.conf |
# 新規作成 WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py |
[root@localhost ~]# systemctl restart httpd |
[root@localhost ~]# vi /var/www/html/test_wsgi.py |
# 新規作成 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' \ 'mod_wsgi Test Page\n' \ '</div>\n' \ '</body>\n' \ '</html>\n' response_header = [('Content-type','text/html')] start_response(status,response_header) return [html] |
例として、「cent」ユーザー所有「/home/cent/venv/testproject」配下の「testapp」を動作させるよう設定します。
設定後はテストページにアクセスして動作確認してください。
[root@localhost ~]# vi /etc/httpd/conf.d/django.conf |
# 新規作成 WSGIDaemonProcess testapp python-path=/home/cent/venv/testproject:/home/cent/venv/lib/python2.7/site-packages WSGIProcessGroup testapp WSGIScriptAlias /django /home/cent/venv/testproject/testproject/wsgi.py <Directory /home/cent/venv/testproject> Require all granted </Directory> |
[root@localhost ~]# systemctl restart httpd |