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

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 2명의 중간 판 7개는 보이지 않습니다)
5번째 줄: 5번째 줄:


==httpd.conf 파일 수정==
==httpd.conf 파일 수정==
<source lang='bash'>
<syntaxhighlight lang='bash'>
vi /etc/httpd/conf/httpd.conf
vi /etc/httpd/conf/httpd.conf
</source>
</syntaxhighlight>
;변경 전
;변경 전
<source lang='xorg_conf'>
<syntaxhighlight lang='aconf'>
<Directory "/var/www/html">
<Directory "/var/www/html">
Options Indexes FollowSymLinks
Options Indexes FollowSymLinks
16번째 줄: 16번째 줄:
Allow from all
Allow from all
</Directory>
</Directory>
</source>
</syntaxhighlight>
;변경 후
;변경 후
<source lang='xorg_conf'>
<syntaxhighlight lang='aconf'>
<Directory "/var/www/html">
<Directory "/var/www/html">
Options Indexes FollowSymLinks
Options Indexes FollowSymLinks
29번째 줄: 29번째 줄:
PythonDebug On
PythonDebug On
</Directory>
</Directory>
</source>
</syntaxhighlight>
:→ [[.psp]] 파일은 mod_python.psp 핸들러가 처리
:→ [[.psp]] 파일은 mod_python.psp 핸들러가 처리
:→ [[.py]] 파일은 mod_python.cgihandler 핸들러가 처리
:→ [[.py]] 파일은 mod_python.cgihandler 핸들러가 처리


==아파치 재시작==
==아파치 재시작==
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# service httpd restart
[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
</source>
</syntaxhighlight>


==hello.py 테스트==
==hello.py 테스트==
* 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
* 아래 내용 참고하여 /var/www/html/hello.py 파일 생성
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# 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>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# curl http://localhost/hello.py
[root@zetawiki ~]# curl http://localhost/hello.py
Hello, Python!
Hello, Python!
</source>
</syntaxhighlight>


==hello.psp 테스트==
==hello.psp 테스트==
* 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
* 아래 내용 참고하여 /var/www/html/hello.psp 파일 생성
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# cat /var/www/html/hello.psp
[root@zetawiki ~]# cat /var/www/html/hello.psp
<html>
<html>
<body>
<body>
61번째 줄: 61번째 줄:
</body>
</body>
</html>
</html>
</source>
</syntaxhighlight>
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# curl http://localhost/hello.psp
[root@zetawiki ~]# curl http://localhost/hello.psp
<html>
<html>
<body>
<body>
69번째 줄: 69번째 줄:
</body>
</body>
</html>
</html>
</source>
</syntaxhighlight>


==mod_python.publisher 사용==
==mod_python.publisher 사용==
*mod_python.cgihandler 대신 mod_python.publisher를 사용할 수도 있다.
*mod_python.cgihandler 대신 mod_python.publisher를 사용할 수도 있다.
<source lang='bash'>
<syntaxhighlight lang='bash'>
vi /etc/httpd/conf/httpd.conf
vi /etc/httpd/conf/httpd.conf
</source>
</syntaxhighlight>
;변경 전
;변경 전
<source lang='xorg_conf'>
<syntaxhighlight lang='aconf'>
PythonHandler mod_python.cgihandler | .py
PythonHandler mod_python.cgihandler | .py
</source>
</syntaxhighlight>
;변경 후
;변경 후
<source lang='xorg_conf'>
<syntaxhighlight lang='aconf'>
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.publisher | .py
</source>
</syntaxhighlight>
*핸들러 코드 작성
*핸들러 코드 작성
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@jmnote ~]# cat /var/www/html/hello2.py
[root@zetawiki ~]# cat /var/www/html/hello2.py
from mod_python import apache
from mod_python import apache


96번째 줄: 96번째 줄:
req.write("<body>\n")
req.write("<body>\n")
req.write("</html>\n")
req.write("</html>\n")
</source>
</syntaxhighlight>


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


==같이 보기==
==같이 보기==
*[[리눅스 mod_python 설치]]
*[[리눅스 mod_python 설치]]
*[[PSP]]
*[[파이썬 서버 페이지 PSP]]


==참고 자료==
==참고==
*http://mydoc.digimoon.net/board/skin/ggambo7002_board/print.php?id=board&no=550
*http://mydoc.digimoon.net/board/skin/ggambo7002_board/print.php?id=board&no=550


[[분류: mod_python]]
[[분류: mod_python]]

2021년 9월 24일 (금) 23:24 기준 최신판

아파치 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 }}