태그 보관물: mod-wsgi

mod-wsgi

Ubuntu에서 Python 용 Mod_WSGI를 설정하는 방법

우분투 상자에 MOD_WSGI를 설정하려고합니다. http://ubuntuforums.org/showthread.php?t=833766 에서 찾은 다음 단계를 수행해야한다고 말한 단계를 찾았습니다.

  1. sudo apt-get 설치 libapache2-mod-wsgi
  2. sudo a2enmod mod-wsgi
  3. sudo /etc/init.d/apache2 재시작
  4. sudo gedit / etc / apache2 / sites-available / default 및 디렉토리 업데이트
<Directory /var/www/>
  Options Indexes FollowSymLinks MultiViews ExecCGI

  AddHandler cgi-script .cgi
  AddHandler wsgi-script .wsgi

  AllowOverride None
  Order allow,deny
  allow from all
</Directory>
  1. sudo /etc/init.d/apache2 재시작
  2. 로 test.wsgi를 만들었습니다.

    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)
    
        return [output]
    

2 단계는 apt-get이 찾더라도 mod-wsgi를 찾을 수 없다고 표시하므로 실패합니다. 단계를 계속 수행하면 Python 앱은 브라우저에서 일반 텍스트로 표시됩니다.

내가 잘못한 아이디어가 있습니까?


편집 : 질문에 대한 결과

automatedtester@ubuntu:~$ dpkg -l libapache2-mod-wsgi
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version                                Description
+++-======================================-======================================-============================================================================================
ii  libapache2-mod-wsgi                    2.5-1                                  Python WSGI adapter module for Apache
automatedtester@ubuntu:~$ dpkg -s libapache2-mod-wsgi
Package: libapache2-mod-wsgi
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 376
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Architecture: i386
Source: mod-wsgi
Version: 2.5-1
Depends: apache2, apache2.2-common, libc6 (>= 2.4), libpython2.6 (>= 2.6), python (>= 2.5), python (<< 2.7)
Suggests: apache2-mpm-worker | apache2-mpm-event
Conffiles:
 /etc/apache2/mods-available/wsgi.load 06d2b4d2c95b28720f324bd650b7cbd6
 /etc/apache2/mods-available/wsgi.conf 408487581dfe024e8475d2fbf993a15c
Description: Python WSGI adapter module for Apache
 The mod_wsgi adapter is an Apache module that provides a WSGI (Web Server
 Gateway Interface, a standard interface between web server software and
 web applications written in Python) compliant interface for hosting Python
 based web applications within Apache. The adapter provides significantly
 better performance than using existing WSGI adapters for mod_python or CGI.
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Homepage: http://www.modwsgi.org/
automatedtester@ubuntu:~$ sudo a2enmod libapache2-mod-wsgi
ERROR: Module libapache2-mod-wsgi does not exist!
automatedtester@ubuntu:~$ sudo a2enmod mod-wsgi
ERROR: Module mod-wsgi does not exist!

RMYates에 대한 추가 편집

automatedtester@ubuntu:~$ apache2ctl -t -D DUMP_MODULES
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_worker_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgid_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 python_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK
automatedtester@ubuntu:~$



답변

나는 이것이 1 년이 지난 mod_wsgi apt-get 패키지의 알려진 버그라는 것을 발견했습니다! http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg1147225.html에 자세한 내용이 있습니다. apt-get 패키지에는 wsgi.load 파일이 없으므로 위 링크의 단계를 수행하여 작성해야합니다.

도와 주신 모든 분들께 감사드립니다!


답변

모듈이 실제로 제대로로드되었는지 확인하십시오 :

apache2ctl -t -D DUMP_MODULES


답변

내가 볼 수있는 한, mod_wsgi 모듈을에로드하지 않았습니다 httpd.conf.

먼저 wsgi 파일을 mods-enabledApache 디렉토리에 추가하려고 시도했습니다 .

sudo ln -s /etc/apache2/mods-available/wsgi.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/wsgi.conf /etc/apache2/mods-enabled

그런 다음 Apache를 다시 시작 하면 작동합니다.


답변

먼저 WSGI 모듈이 실제로 설치 되었는지 확인하십시오 .

dpkg -l libapache2-mod-wsgi

이름, 버전 등을 포함한 출력을 제공해야합니다. 이름 왼쪽의 문자를 찾으십시오. 이는 패키지의 현재 상태를 나타냅니다. 수동으로 확인하려면 / etc / apache2 / mods-available /에서 wsgi.confwsgi.load를 모두 확인하십시오 . 만약 존재한다면, / etc / apache2 / mods-enabled /에 해당 심볼릭 링크가 있어야합니다 .

중 하나를 설정해야 하지 아파치가 통역을 찾을 수없는 경우 아파치를 통해 파이썬 코드를 해석 할 수 없습니다 – 먼저 고정하여 시작 존재한다. 또한 구성한 AddHandler 지시문이 주어지면 test.py 스크립트가 작동하지 않습니다. 이 지시문은 아파치에게 특정 확장자의 파일을 관련 처리기 에 전달하도록 지시 합니다. 스크립트를 test.wsgi로 만들 거나 AddHandler 지시문을 변경하십시오 .


답변

실제로 mod_wsgi가로드되도록 LoadModule 행을 추가 했습니까? 실제 오류 메시지는 무엇이며 어디에서 왔습니까? 만나다:

http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide

저수준 지침. 바이너리 패키지를 사용하고 있으므로 컴파일을 건너 뛸 수 있지만 여전히 mod_wsgi를로드해야합니다. 이 작업을 수행 할 수있는 위치 / 방법은 Linux 배포판에 따라 어느 정도 결정됩니다. 이 안내서를 기반으로 다음을 실행해야합니다.

sudo a2enmod mod-wsgi
sudo /etc/init.d/apache2 restart

실제로 그렇게 했습니까?


편집하다

질문을 다시 읽으면 분명합니다. .wsgi 확장자를 가진 파일은 mod_wsgi에 의해 처리된다고 말했지만 파일에 .py 확장자를 부여했습니다. .wsgi를 대신 사용하십시오.


답변

파이썬의 구문을 먼저 볼 수 있습니다. 함수 정의 후에 실제로 4 개의 공백이 있는지 확인하십시오. 파이썬 파일을 터미널을 통해 먼저 실행하여 확인하십시오.

$ python /var/www/py/wsgi_handler.wsgi

오류가 나타나지 않으면 웹 브라우저를 통해 실행하십시오.

http : // localhost / wsgi /

그리고 아파치 구성 / 가상 호스트 파일에 대해 뭔가를 놓친 것 같습니다. 이것을 태그 안에 넣으십시오

WSGIScriptAlias /wsgi /var/www/py/wsgi_handler.py

그런데 wsgi 모듈을 설치할 때 apt에는 아무런 문제가 없습니다. 방금 테스트했으며 웹 브라우저에서 Python 스크립트를 성공적으로 실행했습니다.


답변

이것이 관련이 있는지 확실하지 않지만 실행 후 :

apt-get install libapache2-mod-wsgi

… 다음 파일이 존재 하지 않았습니다 :

/etc/apache2/mods-available/wsgi.conf
/etc/apache2/mods-available/wsgi.load

다시 설치해도 누락 된 파일이 바뀌지 않는 것 같습니다. 기묘한! 그러나 purge트릭을하는 것처럼 보였습니다.

apt-get install libapache2-mod-wsgi
apt-get purge libapache2-mod-wsgi
apt-get install libapache2-mod-wsgi

# ls /etc/apache2/mods-available/ | grep wsgi
wsgi.conf
wsgi.load