"아파치 mod python 연동"의 두 판 사이의 차이

잔글 (로봇: 자동으로 텍스트 교체 (-[root@jmnote +[root@zetawiki))
잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
34번째 줄: 34번째 줄:


==아파치 재시작==
==아파치 재시작==
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# service httpd restart
[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Stopping httpd:                                            [  OK  ]
42번째 줄: 42번째 줄:
==hello.py 테스트==
==hello.py 테스트==
* 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
* 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# cat /var/www/html/hello.py
[root@zetawiki ~]# cat /var/www/html/hello.py
print "Content-type: text/html\n"
print "Content-type: text/html\n"
print "Hello, Python!"
print "Hello, Python!"
</source>
</source>
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# curl http://localhost/hello.py
[root@zetawiki ~]# curl http://localhost/hello.py
Hello, Python!
Hello, Python!
54번째 줄: 54번째 줄:
==hello.psp 테스트==
==hello.psp 테스트==
* 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
* 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# cat /var/www/html/hello.psp
[root@zetawiki ~]# cat /var/www/html/hello.psp
<html>
<html>
62번째 줄: 62번째 줄:
</html>
</html>
</source>
</source>
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# curl http://localhost/hello.psp
[root@zetawiki ~]# curl http://localhost/hello.psp
<html>
<html>
85번째 줄: 85번째 줄:
</source>
</source>
*핸들러 코드 작성
*핸들러 코드 작성
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# cat /var/www/html/hello2.py
[root@zetawiki ~]# cat /var/www/html/hello2.py
from mod_python import apache
from mod_python import apache
99번째 줄: 99번째 줄:


* 아파치를 재시작한 후 테스트
* 아파치를 재시작한 후 테스트
<source lang='cli'>
<source lang='console'>
[root@zetawiki ~]# curl http://localhost/hello2.py/handler
[root@zetawiki ~]# curl http://localhost/hello2.py/handler
<html>
<html>

2016년 3월 29일 (화) 14:05 판

아파치 mod_python 연동

1 mod_python 설치

2 httpd.conf 파일 수정

vi /etc/httpd/conf/httpd.conf
변경 전
<Directory "/var/www/html">
	Options Indexes FollowSymLinks
	AllowOverride None
	Order allow,deny
	Allow from all
</Directory>
변경 후
<Directory "/var/www/html">
	Options Indexes FollowSymLinks
	AllowOverride None
	Order allow,deny
	Allow from all
	AddHandler mod_python .psp .psp_ .py
	PythonHandler mod_python.psp | .psp .psp_
	PythonHandler mod_python.cgihandler | .py
	PythonDebug On
</Directory>
.psp 파일은 mod_python.psp 핸들러가 처리
.py 파일은 mod_python.cgihandler 핸들러가 처리

3 아파치 재시작

[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

4 hello.py 테스트

  • 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
[root@zetawiki ~]# cat /var/www/html/hello.py
print "Content-type: text/html\n"
print "Hello, Python!"
[root@zetawiki ~]# curl http://localhost/hello.py
Hello, Python!

5 hello.psp 테스트

  • 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
[root@zetawiki ~]# cat /var/www/html/hello.psp
<html>
<body>
<h2><%= 'Hello, PSP!' %></h2>
</body>
</html>
[root@zetawiki ~]# curl http://localhost/hello.psp
<html>
<body>
<h2>Hello, PSP!</h2>
</body>
</html>

6 mod_python.publisher 사용

  • mod_python.cgihandler 대신 mod_python.publisher를 사용할 수도 있다.
vi /etc/httpd/conf/httpd.conf
변경 전
	PythonHandler mod_python.cgihandler | .py
변경 후
	PythonHandler mod_python.publisher | .py
  • 핸들러 코드 작성
[root@zetawiki ~]# cat /var/www/html/hello2.py
from mod_python import apache

def handler(req):
	req.content_type = 'text/html'
	req.write("<html>\n")
	req.write("<body>\n")
	req.write("Hello, Publisher!\n")
	req.write("<body>\n")
	req.write("</html>\n")
  • 아파치를 재시작한 후 테스트
[root@zetawiki ~]# curl http://localhost/hello2.py/handler
<html>
<body>
Hello, Publisher!
<body>
</html>

7 같이 보기

8 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}