- 아파치 mod_python 연동
1 mod_python 설치[ | ]

2 httpd.conf 파일 수정[ | ]
Bash
Copy
vi /etc/httpd/conf/httpd.conf
- 변경 전
aconf
Copy
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
- 변경 후
aconf
Copy
<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>
3 아파치 재시작[ | ]
Console
Copy
[root@zetawiki ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
4 hello.py 테스트[ | ]
- 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
Console
Copy
[root@zetawiki ~]# cat /var/www/html/hello.py
print "Content-type: text/html\n"
print "Hello, Python!"
Console
Copy
[root@zetawiki ~]# curl http://localhost/hello.py
Hello, Python!
5 hello.psp 테스트[ | ]
- 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
Console
Copy
[root@zetawiki ~]# cat /var/www/html/hello.psp
<html>
<body>
<h2><%= 'Hello, PSP!' %></h2>
</body>
</html>
Console
Copy
[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를 사용할 수도 있다.
Bash
Copy
vi /etc/httpd/conf/httpd.conf
- 변경 전
aconf
Copy
PythonHandler mod_python.cgihandler | .py
- 변경 후
aconf
Copy
PythonHandler mod_python.publisher | .py
- 핸들러 코드 작성
Console
Copy
[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")
- 아파치를 재시작한 후 테스트
Console
Copy
[root@zetawiki ~]# curl http://localhost/hello2.py/handler
<html>
<body>
Hello, Publisher!
<body>
</html>
7 같이 보기[ | ]
8 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.