티스토리 뷰

programming/Scripts

wsgi with apache

Jacob_baek 2016. 7. 20. 21:12


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 라는 메세지가 출력된다.


'programming > Scripts' 카테고리의 다른 글

Bash shell variables looks like an array  (0) 2022.12.19
powershell  (0) 2019.08.14
parsing xml  (0) 2013.07.12
python for ssh  (0) 2012.07.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함