2013-01-19 50 views
7

我想安裝Python和WSGI與Apache特定的目錄,但我收到以下錯誤:與WSGI在Apache上設置的Python目錄

mod_wsgi (pid=3857): Target WSGI script '/var/www/test/test.py' does not contain WSGI application 'application'. 

我test.py包含:

print 'Hello, World!' 

而且我wsgi.conf包含:

LoadModule wsgi_module modules/mod_wsgi.so 

WSGIPythonHome /usr/local/bin/python2.7 

Alias /test/ /var/www/test/test.py 

<Directory /var/www/test> 
    SetHandler wsgi-script 
    Options ExecCGI 
    Order deny,allow 
     Allow from all 
</Directory> 

在最嚴重的是,有趣的是,Web瀏覽器返回一個「404 Not Found」錯誤,但幸好error_log更有啓發性。

我在做什麼錯?

回答

13

您正在使用WSGI,好像它是CGI(奇怪的是沒有標題)。

你需要做什麼,你眼前的問題是適應從http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

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] 

所以下面你有application存在。

並從引用的文檔。

Note that mod_wsgi requires that the WSGI application entry point be called 'application'. If you want to call it something else then you would need to configure mod_wsgi explicitly to use the other name. Thus, don't go arbitrarily changing the name of the function. If you do, even if you set up everything else correctly the application will not be found.

+0

謝謝!說得通。 – hanleyhansen

+1

WSGICallableObject appfunctionname – arivero