I'm trying to setup python / apache / WSGI on windows.
I have the following installed, all 32-bit and vc9:
- Apache 2.4
- Python 2.7.9
- Mod_WSGI.so in the modules folder.
http://localhost/ Displays the Apache Haus web page successfully — Apache is running and serving.
Here is my "Hello World" python script:
def application(environ, start_response):
status = '200 OK'
output = 'This is my Website!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Here is my Apache config:
WSGIScriptAlias /wsgi "C:/wsgi_app/wsgi_app.py"
<Directory "C:/wsgi_app">
AllowOverride None
Options MultiViews
Require all granted
</Directory>
This version will display the file in plain-text, rather than interpreting it.
If I change options to none…
WSGIScriptAlias /wsgi "C:/wsgi_app/wsgi_app.py"
<Directory "C:/wsgi_app">
AllowOverride None
Options none
Require all granted
</Directory>
I get 404 Not Found on http://localhost/wsgi
The apache error log doesn't have much that seems too useful for troubleshooting.
[Wed Feb 10 16:17:49.293987 2016] [wsgi:warn] [pid 4448:tid 336] mod_wsgi: Compiled for Python/2.7.9+.
[Wed Feb 10 16:17:49.293987 2016] [wsgi:warn] [pid 4448:tid 336] mod_wsgi: Runtime using Python/2.7.9.
[Wed Feb 10 16:17:49.325187 2016] [mpm_winnt:notice] [pid 4448:tid 336] AH00354: Child: Starting 64 worker threads.
[Wed Feb 10 16:17:52.538793 2016] [wsgi:error] [pid 4448:tid 1040] [client ::1:54402] Target WSGI script not found or unable to stat: C:/wsgi_app/wsgi_app.py
"LoadModule access_compat_module modules/mod_access_compat.so" is uncommented, if that matters.
Any ideas on how to get this page to load / other apache config changes to try?
Do I need to change a python config somewhere?
Best Answer
From the error you are getting:
It is highly likely that you have no file with the name "wsgi_app.py" in the "C:/wsgi_app/" directory.
Now what does the
Options Multiviews
do?Here is a quote from Apache 2.4 documentation:
As you can see from the above explanation, when Multiviews option is enabled, and since a file named
wsgi_app.py
doesn't exist, the server will try to look for files namedwsgi_app.py.*
.I suspect you have a file named
wsgi_app.py.txt
in the directory, and it's content get's displayed. You have probably created a text file in windows to create the wsgi_app.py file. In Windows when folder option "hide known file type extensions" is enabled, then it will hide the.txt
extension of a file. As a result, a file namedwsgi_app.py.txt
will just be shown aswsgi_app.py
.When there is no Multiviews option anymore, the server is looking for a file exactly named "wsgi_app.py", and returning the error, being unable to find it.