#apacheとmod_wsgiの連携をして、ブラウザからアクセスした際に、pythonのファイルを実行して返すサーバーを実装したいです。フレームワークは使用していません。
apacheは2.4.48でmod_wsgiは4.9.0のバージョンを使っています。
#まずmod_wsgiを使わず、apacheのHostとVirtualHostそれぞれにアクセスし、htmlのファイルを返すこと確認しました。
具体的には、curl localhost:80,curl localhost:81を入力して、設定したindex.htmlが表示されました。
#次の段階として、mod_wsgiを連携させたいと考えています。
mod_wsgiは、ソースコードからダウンロードanaconda4.10.1において仮想環境を構築し、その仮想環境の中にpipを使ってインストールしました。
また、この仮想環境にはpython3.9.6もインストールしました。
#このような環境の下で、以下のような4つの設定をしました。
###(1)WSGIScriptAliasの設定(/usr/local/apache2/conf/extra/httpd-vhosts.conf)
Listen 81 <VirtualHost *:81> ServerName wsgiapp.example.com DocumentRoot "/usr/local/vhosts" <Directory "/usr/local/vhosts"> AllowOverride All Require all granted </Directory> Alias /vhalias "/usr/local/vhalias" <Directory "/usr/local/vhalias"> AllowOverride All Require all granted </Directory> WSGIScriptAlias /myapp "/usr/local/www/myapp.wsgi" <Directory "/usr/local/www"> AllowOverride All Require all granted </Directory> </VirtualHost>
###(2)Load moduleの設定(/usr/local/apache2/conf/httpd.conf)
LoadModule wsgi_module /home/vagrant/anaconda3/envs/gaia/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so
このディレクトリはmod_wsgi-express module-configによって確認したものを使っています。
###(3)Include conf/extra/httpd-vhosts.confはコメントアウトを解除(/usr/local/apache2/conf/httpd.conf)
# Virtual hosts Include conf/extra/httpd-vhosts.conf
###(4)myapp.wsgiの設定(/usr/local/www/myapp.wsgi)
def application(environ, start_response): status = '200 OK' output = b'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
#このように設定し、apacheを再起動すると、curl localhost:80,curl localhost:81,curl localhost:81/myappと打っても何も反応がないです。エラーが発生するわけでもないです。
また設定の方法はいろいろ試しており、
(1)httpd-vhosts.conf側にLoad moduleの設定、httpd-vhosts.conf側にWSGIScriptAlias
(2)httpd.confとhttpd-vhosts.conf側の両方にLoad moduleの設定、httpd-vhosts.conf側にWSGIScriptAlias
のどの場合も同じように動作しないことがわかっています。
#設定方法のわかる方がいらっしゃれば教えていただければと思います。よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー