I have set up mod_wsgi + apache on Ubuntu with SSL enabled. And it works.
I am able to see Hello World.
Now i have also keyed in index.py as follows and done a soft link to
index.wsgi. i really want to work in this way and p, just bear with me
till i get it to run for few months and onwards.
Thank you
Nitin
-------------------
In Apache 's httpd.conf I have also set 'DirectoryIndex index.html
index.wsgi index.py'
On entering https://healthcare.in/index.py
***
500 Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, y...@healthcare.in and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error log.
****
index.py
----------------
import os
from datetime import datetime
import re
class Handles:
def do(self, environ, start_response):
uri = environ['REQUEST_URI']
html = "<html><head><title>Index of %s</title></head><body>" % uri
html += "<h1>Index of %s</h1>" % uri
html += "<table border='0'>"
html += '<tr><th>Last
Modified</th><th>Size</th>Description</th><th>Webifiable</th><tr><th
colspan="6"><hr></th></tr>
html += '<tr><td><a href="..">Parent
Directory</a></td><td> </td><td align="right"> -
</td><td> </td><td>&n
html += '<tr><th colspan="6"><hr></th></tr>'
html += "</tables>"
html += "</body></html>"
output = html
mimeType = 'text/html'
status = '200 OK'
response_headers = [('Content-type', mimeType),
('content-Length' , str(len(output)))]
start_response(status, start_response):
return [output]
def application(environ, start_response):
handler = Handler()
return handler.do(environ, start_response)
Graham
> --
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>
>
[Wed Oct 20 21:22:57 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scrip
[Wed Oct 20 21:26:25 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scrip
[Thu Oct 21 10:41:28 2010] [warn] RSA server certificate CommonName
(CN) `ubuntu' does NOT match server name!?
[Thu Oct 21 10:41:28 2010] [notice] suEXEC mechanism enabled (wrapper:
/opt/apache2215/bin/suexec)
[Thu Oct 21 10:41:28 2010] [notice] Digest: generating secret for
digest authentication ...
[Thu Oct 21 10:41:28 2010] [notice] Digest: done
[Thu Oct 21 10:41:29 2010] [warn] RSA server certificate CommonName
(CN) `ubuntu' does NOT match server name!?
[Thu Oct 21 10:41:29 2010] [warn] pid file
/opt/apache2215/logs/httpd.pid overwritten -- Unclean shutdown of
previous Apache
[Thu Oct 21 10:41:29 2010] [notice] Apache/2.2.15 (Unix)
mod_ssl/2.2.15 OpenSSL/0.9.8k DAV/2 mod_wsgi/3.2 Python/2.6.5 confi
[Thu Oct 21 10:41:45 2010] [error] [client 192.168.1.9] Symbolic link
not allowed or link target not accessible: /home/dev/w
[Thu Oct 21 10:41:45 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scrip
[Thu Oct 21 10:41:50 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1329): Target WSGI script '/home/dev/wsgi-scripts/inde
[Thu Oct 21 10:42:36 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:36 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:36 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:36 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:36 2010] [notice] caught SIGTERM, shutting down
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
[Thu Oct 21 10:42:37 2010] [error] Exception KeyError:
KeyError(139750291932960,) in <module 'threading' from '/usr/lib/pyth
Nitin
>> start_response(status, response_headers)
Looks like you haven't enabled FollowSymLinks in Apache or your
symlink is broken.
Graham
<Directory "/opt/apache2215/htdocs">
Options Indexes FollowSymLinks
</Directory>
<VirtualHost 192.168.1.6:80>
ServerName www.healthcare.in
ServerAlias healthcare.in
Redirect / https://www.healthcare.in/index.wsgi
.
.
<Directory /home/dev/wsgi-scripts>
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
.
.
</VirtualHost>
<VirtualHost 192.168.1.6:443>
DocumentRoot "/home/dev/wsgi-scripts/"
ServerName www.healthcare.in
.
.
.
<Directory /home/dev/wsgi-scripts>
Options FollowSymLinks
Order allow,deny
Allow from all
SSLOptions +StdEnvVars
Options ExecCGI
SetHandler wsgi-script
WSGIProcessGroup healthcare.in
</Directory>
</VirtualHost>
Reg
Nitin
[Thu Oct 21 23:18:43 2010] [notice] Apache/2.2.15 (Unix)
mod_ssl/2.2.15 OpenSSL/0.9.8k DAV/2 mod_wsgi/3.2 Python/2.6.5
configured -- resuming normal operations
[Thu Oct 21 23:18:47 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1794): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:18:47 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
[Thu Oct 21 23:20:13 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
[Thu Oct 21 23:20:19 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1796): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:28:20 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
[Thu Oct 21 23:34:15 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
[Thu Oct 21 23:34:16 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1797): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:34:19 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1792): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:34:28 2010] [error] Exception KeyError:
KeyError(140078841251616,) in <module 'threading' from
'/usr/lib/python2.6/threading.pyc'> ignored
[Thu Oct 21 23:34:28 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1793): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:40:19 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
[Thu Oct 21 23:40:20 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1793): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
[Thu Oct 21 23:40:21 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1792): Target WSGI script '/home/dev/wsgi-scripts/index.py' does
not contain WSGI application 'application'.
cat: last: No such file or directory
--------------------------------------
#!/usr/bin/env python
import os
from datetime import datetime
import re
class Handler:
def do(self, environ, start_response):
uri = environ['REQUEST_URI']
html = "<html><head><title>Index of %s</title></head><body>" % uri
html += "<h1>Index of %s</h1>" % uri
html += "<table border='0'>"
html += '<tr><th>Last
Modified</th><th>Size</th>Description</th><th>Webifiable</th><tr><th
colspan="6"><hr></th></tr>
html += '<tr><td><a href="..">Parent
Directory</a></td><td> </td><td align="right"> -
</td><td> </td><td>&n
html += '<tr><th colspan="6"><hr></th></tr>'
html += "</tables>"
html += "</body></html>"
output = html
mimeType = "text/html"
status = "200 OK"
response_headers = [("Content-type", mimeType),
("Content-length" , str(len(output)))]
start_response(status, response_headers)
return [output]
def application(environ, start_response):
handler = Handler()
return handler.do(environ, start_response)
### Do I REALLY need to use wsgiref ??? Else how do I run 'application' ???
if __name__ == '__main__' :
## Handler() ;;; will this do
import wsgiref.handlers
wsgiref.handlers.CGIHandler().run(application)
>>
>> <Directory "/opt/apache2215/htdocs">
>> Options Indexes FollowSymLinks
>> </Directory>
FollowSymLinks changed to MultiViews
TIA
Nitin
Or a 4th way to just un-indent the definition of the application()
method so it is instead a top-level function:
def application(environ, start_response):
handler = Handler()
return handler.do(environ, start_response)
Actually, I'm wondering if that wasn't what was intended all along, but
there was just an inadvertent indentation error.
--
Deron Meranda
http://deron.meranda.us/
Given that there was no 'self' argument, probably likely. :-)
Graham
Thanks
Nitin
500 Internal Server Error
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=4210, process='healthcare.in',
application='www.healthcare.in|/index.py'): Failed to parse WSGI
script file '/home/dev/wsgi-scripts/index.py'.
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=4210): Exception occurred processing WSGI script
'/home/dev/wsgi-scripts/index.py'.
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9] File
"/home/dev/wsgi-scripts/index.py", line 31
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9] def
application(environ, start_response):
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9]
^
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9]
IndentationError: unindent does not match any outer indentation level
[Fri Oct 22 23:35:04 2010] [error] [client 192.168.1.9] Target WSGI
script not found or unable to stat: /home/dev/wsgi-scripts/favicon.ico
IS there some editor which does not insert some character without my
knowledge.<frustrated>
------------------------------------------
#!/usr/bin/env python
import os
from datetime import datetime
import re
class Handler:
def do(self, environ, start_response):
uri = environ['REQUEST_URI']
html = "<html><head><title>Index of %s</title></head><body>" % uri
html += "<h1>Index of %s</h1>" % uri
html += "<table border='0'>"
html += '<tr><th>Last
Modified</th><th>Size</th>Description</th><th>Webifiable</th><tr><th
colspan="6"><hr></th></tr>'
html += '<tr><td><a href="..">Parent
Directory</a></td><td> </td><td align="right"> -
</td><td> </td><td> </td></tr>'
html += '<tr><th colspan="6"><hr></th></tr>'
html += "</tables>"
html += "</body></html>"
output = html
mimeType = "text/html"
status = "200 OK"
response_headers = [("Content-type", mimeType),
("Content-length", str(len(output)))]
def application(self, environ, start_response): <line on which all
kind of trials with no luck>
start_response(status, response_headers)
return [output]
Error is "500 Internal Server Error" and in end, error_log entries are pasted.
< not ready to give up .... yet >
As I keep getting familiar with the development architecture, i shall
trouble the list , lot less :)
TIA
Nitin
my httpd.conf
-----------------------
ServerRoot "/opt/apache2215"
Listen 192.168.1.6:80
LoadModule wsgi_module modules/mod_wsgi.so
User daemon
Group daemon
ServerAdmin y...@example.com
ServerName www.healthcare.in
DocumentRoot "/opt/apache2215/htdocs"
<Directory />
Options MultiViews
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/opt/apache2215/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.wsgi index.py
</IfModule>
<Directory "/opt/apache2215/cgi-bin">
AllowOverride None
Options MultiViews
Order allow,deny
Allow from all
</Directory>
NameVirtualHost 192.168.1.6:80
<VirtualHost 192.168.1.6:80>
ServerName www.healthcare.in
ServerAlias healthcare.in
Redirect / https://www.healthcare.in/index.wsgi
WSGIDaemonProcess healthcare.in processes=6 threads=15 display-name=%{GROUP}
WSGIProcessGroup healthcare.in
WSGIScriptAlias / /home/dev/wsgi-scripts/
<Directory /home/dev/wsgi-scripts>
Options MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Listen 192.168.1.6:443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:/tmp/ssl_scache(512000)"
SSLSessionCacheTimeout 300
SSLMutex "file:/tmp/ssl_mutex"
<VirtualHost 192.168.1.6:443>
DocumentRoot "/home/dev/wsgi-scripts/"
ServerName www.healthcare.in
ServerAdmin y...@healthcare.in
SSLEngine on
SSLCipherSuite
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile "/etc/cups/ssl/server.crt"
SSLCertificateKeyFile "/etc/cups/ssl/server.key"
<FilesMatch "\.(cgi|shtml|phtml|php|py|pyc)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /home/dev/wsgi-scripts>
Options MultiViews
Order allow,deny
Allow from all
SSLOptions +StdEnvVars
Options ExecCGI
SetHandler wsgi-script
WSGIProcessGroup healthcare.in
</Directory>
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
==================================================
index.py
----------
#!/usr/bin/env python
import os, re
from datetime import datetime
class Handler:
def do(self, environ, start_response):
uri = environ['REQUEST_URI']
html = "<html><head><title>Index of %s</title></head><body>" % uri
html += "<h1>Index of %s</h1>" % uri
html += "<table border='0'>"
html += '<tr><th>Last
ModifiedL</t><th>Size</th><th>Description</th><th>Webifiable</th><tr><th
colspan="6"><hr></th></tr>'
html += '<tr><td><a href="..">Parent
Directory</a></td><td> </td><td align="right"> -
</td><td> </td><td> </td></tr>'
html += '<tr><th colspan="6"><hr></th></tr>'
html += "</tables>"
html += "</body></html>"
output = html
mimeType = "text/html"
status = "200 OK"
response_headers = [("Content-type", mimeType),
("Content-length", str(len(output)))]
application = Handler()
"""
(environ, status_response):
start_response(status, response_header)
return [output]
"""
---------------------------------------
from /opt/apache2215/log/error_log
[Sun Oct 24 11:50:12 2010] [error] [client 192.168.1.9] mod_wsgi
(pid=1414): Exception occurred processing WSGI script
'/home/dev/wsgi-scripts/index.py'.
[Sun Oct 24 11:50:12 2010] [error] [client 192.168.1.9] Traceback
(most recent call last):
[Sun Oct 24 11:50:12 2010] [error] [client 192.168.1.9] File
"/home/dev/wsgi-scripts/index.py", line 24, in <module>
[Sun Oct 24 11:50:12 2010] [error] [client 192.168.1.9]
application = Handler(application)
[Sun Oct 24 11:50:12 2010] [error] [client 192.168.1.9] NameError:
name 'application' is not defined
Hello,
Please explain how the do method will be called?
There must be a callable in the wsgi file named "application"... As it stands, you have an instance of a "handler" class that cannot be called.
Consider refactoring as a simle function called "application" just to role out those issues... Theb, once working, expand it.
By the way, wsgi itself is a bit raw, so unless your main goal is to develop another framework, I strongly suggest you use a framework.
Both bottle and appstruct are very lightweight. I can help you off list with the latter...
-jg
class
def func()
_ _init_ _
_ _name_ _ = '_ _main_ _':
_ _call_ _
return
how they get combined and then add them into my code for testing.will
take 2 more days and shall update / request for support on list.
Reg
Nitin