Apache 설정 · 2 min read · Nov 13, 2025

Apache2에 Python 임베딩하기 (mod_python) - 페이지 3

5 OpenSUSE 11

5.1 mod_python 설치하기

mod_python을 설치하려면, 다음 명령어를 실행합니다:

yast -i apache2-mod_python

mod_python을 활성화하려면, /etc/sysconfig/apache2를 열고 APACHE_MODULES 줄에 python을 추가합니다. 예를 들어 다음과 같이:

vi /etc/sysconfig/apache2

| [...] APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user authn_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif ssl suexec userdir php5 rewrite python" [...] |

그 후, 다음을 실행합니다:

SuSEconfig

그리고 Apache를 재시작합니다:

/etc/init.d/apache2 restart

5.2 Apache 구성하기

이제 Apache가 Python 파일을 처리할 수 있도록 구성해야 합니다. 이를 위한 두 가지 방법이 있습니다. 첫 번째(기본) 방법은 Publisher Handler를 사용하는 것입니다. 이는 .py 확장자를 가진 순수 Python 스크립트를 작성할 수 있게 해주며, Apache에 의해 해석됩니다. 두 번째 방법은 PSP Handler입니다. PSP는 Python Server Pages의 약자입니다. 이는 HTML 코드에 Python 코드를 직접 삽입할 수 있게 해주며, PHP와 유사합니다. PSP 파일은 .psp 확장자를 가집니다.

5.2.1 Publisher Handler

Publisher Handler를 활성화하려면, /etc/apache2/conf.d/python.conf에 mod_python 구성을 생성합니다(이 파일은 존재하지 않으므로 생성합니다). 여기서는 기본 OpenSUSE 문서 루트인 /srv/www/htdocs를 지시문에서 사용하고 있습니다 - 필요에 맞게 조정하세요. 중요한 줄은 AddHandler mod_python .py와 PythonHandler mod_python.publisher입니다:

vi /etc/apache2/conf.d/python.conf

| Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On |

주의: 서버에서 ISPConfig(버전 2.2.24 이상)를 사용하는 경우, 해당 파일을 생성하지 마세요. 이는 해당 디렉토리에 대해 mod_python을 전역적으로 활성화하게 됩니다. ISPConfig에서는 웹사이트별로 mod_python을 활성화할 수 있어, 웹사이트가 mod_python을 사용할 수 있는지에 대한 더 많은 제어를 제공합니다.

그 후 Apache를 재시작합니다:

/etc/init.d/apache2 restart

이제 순수 Python 코드가 포함된 작은 Python 테스트 스크립트(예: /srv/www/htdocs/test.py)를 생성합니다…

vi /srv/www/htdocs/test.py

| def index(req): return "Test successful"; |

… 그리고 브라우저에서 호출합니다(예: http://192.168.0.100/test.py). 모든 것이 잘 진행되면, 브라우저에 “Test successful”이 표시되어야 합니다.

5.2.2 PSP Handler

PSP Handler를 활성화하려면, /etc/apache2/conf.d/python.conf에 mod_python 구성을 생성합니다(이 파일은 존재하지 않으므로 생성합니다). 여기서는 기본 OpenSUSE 문서 루트인 /srv/www/htdocs를 지시문에서 사용하고 있습니다 - 필요에 맞게 조정하세요. 중요한 줄은 AddHandler mod_python .psp와 PythonHandler mod_python.psp입니다:

vi /etc/apache2/conf.d/python.conf

| Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all AddHandler mod_python .psp PythonHandler mod_python.psp PythonDebug On |

주의: 서버에서 ISPConfig(버전 2.2.24 이상)를 사용하는 경우, 해당 파일을 생성하지 마세요. 이는 해당 디렉토리에 대해 mod_python을 전역적으로 활성화하게 됩니다. ISPConfig에서는 웹사이트별로 mod_python을 활성화할 수 있어, 웹사이트가 mod_python을 사용할 수 있는지에 대한 더 많은 제어를 제공합니다. 또한 ISPConfig는 PSP Handler를 지원하지 않으며, Publisher Handler를 사용합니다.

그 후 Apache를 재시작합니다:

/etc/init.d/apache2 restart

이제 HTML과 Python 코드가 포함된 작은 PSP 테스트 스크립트(예: /srv/www/htdocs/test.psp)를 생성합니다…

vi /srv/www/htdocs/test.psp

|

<% req.write("Hello!") %>

|

… 그리고 브라우저에서 호출합니다(예: http://192.168.0.100/test.psp). 모든 것이 잘 진행되면, 브라우저에 “Hello!”가 표시되어야 합니다.

6 링크

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.