CentOS7

Apache httpd : Python + mod_wsgi

mod_wsgi (WSGI : Web Server Gateway Interface) をインストールして、Python スクリプトの実行を高速化します。

mod_wsgi をインストールします。

[root@localhost ~]# yum -y install mod_wsgi

例として、/var/www/html/test_wsgi.py が /test_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]

01.png

Django を利用する場合は以下のように設定します。( Django 環境の構築はこちらを参照 )

例として、「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

02.png


添付ファイル: file02.png 86件 [詳細] file01.png 65件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-09-04 (火) 09:54:58