#author("2018-09-04T09:54:37+09:00","","") [[CentOS7]] *Apache httpd : Python + mod_wsgi [#pcd55c76] mod_wsgi (WSGI : Web Server Gateway Interface) をインストールして、Python スクリプトの実行を高速化します。 *mod_wsgi をインストールします。 [#m8767731] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# yum -y install mod_wsgi| *例として、/var/www/html/test_wsgi.py が /test_wsgi でアクセスできるよう設定します。 [#ze020420] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /etc/httpd/conf.d/wsgi.conf| | &br; &color(lightpink){# 新規作成}; &br; WSGIScriptAlias /test_wsgi /var/www/html/test_wsgi.py &br; | |[root@localhost ~]# systemctl restart httpd| *設定したテストスクリプトを作成して動作確認します。 [#te58f8dd] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/test_wsgi.py| | &br; &color(lightpink){# 新規作成}; &br; &br; def application(environ,start_response): &br; status = '200 OK' &br; html = '<html>\n' \ &br; '<body>\n' \ &br; '<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">\n' \ &br; 'mod_wsgi Test Page\n' \ &br; '</div>\n' \ &br; '</body>\n' \ &br; '</html>\n' &br; response_header = [('Content-type','text/html')] &br; start_response(status,response_header) &br; return [html] &br; | &ref(01.png); *Django を利用する場合は以下のように設定します。( Django 環境の構築はこちらを参照 ) [#v903f2cf] 例として、「cent」ユーザー所有「/home/cent/venv/testproject」配下の「testapp」を動作させるよう設定します。 設定後はテストページにアクセスして動作確認してください。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /etc/httpd/conf.d/django.conf| |&color(lightpink){# 新規作成}; &br; &br; WSGIDaemonProcess testapp python-path=/home/cent/venv/testproject:/home/cent/venv/lib/python2.7/site-packages &br; WSGIProcessGroup testapp &br; WSGIScriptAlias /django /home/cent/venv/testproject/testproject/wsgi.py &br; &br; <Directory /home/cent/venv/testproject> &br; Require all granted &br; </Directory> &br; | |[root@localhost ~]# systemctl restart httpd| &ref(02.png);