Configuring Python from WSGI to Apache for a Directory

I am trying to configure Python with WSGI for a specific directory on Apache, but I am getting the following error:

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

My test.py contains:

 print 'Hello, World!' 

And my wsgi.conf contains:

 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> 

Among other things, interestingly enough, the web browser returns a "404 Not Found" error, but, fortunately, error_log is a little more interesting.

What am I doing wrong?

+7
source share
1 answer

You are using WSGI as if it were CGI (weird without headers).

What you need to do as your immediate problem is this: 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] 

So you have an application .

And from the reference document

Note that mod_wsgi requires the entry point of the WSGI application to be called the "application". If you want to call it something else, then you will need to explicitly configure mod_wsgi to use a different name. Thus, do not arbitrarily change the name of the function. if you do, even if you configure everything else correctly, the application will not be found.

+13
source

All Articles