wsgi with apache
apache에서 mod_wsgi 를 통한 서비스를 하는 방법을 알아보자
우선 /etc/httpd/conf.d/01-wsgi.example.com.conf 를 생성한다.
아래는 sample configuration이다.
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName wsgi.example.com
# 아래 설정에서 마지막 argument는 full path를 넣어주는게 편하다. (향후 관리를 위해서도)
WSGIScriptAlias / app.py
</VirtualHost>
실제 python code는 다음과 같다.
(필수적으로 application 이라는 function이 존재해야 하고 response header를 포함한 응답이 return 되어야 한다.)
def application(environ, start_response):
status = '200 OK'
output = 'Hello World! by wsgi'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
* ref : http://stackoverflow.com/questions/14410455/setting-up-python-with-wsgi-on-apache-for-a-directory
이와 같이 설정후 httpd 을 구동시키면
Hello World! by wsgi 라는 메세지가 출력된다.