I had some difficulty getting the mongrel2 + uwsgi + web2py to work because 
uwsgi was not setting all of the environment variables that web2py was 
expecting.

With uWSGI 1.1 some improvements will be made, but e.g. web2py logging is 
depending on REMOTE_ADDRESS and this is not set by uWSGI and web2py fails 
silently.

The attached diff should make things work with older versions of uWSGI as 
well ( I tested 1.0.2.1, 1.0.4 and 1.1-dev-1996)
diff -r 7f492ab789a9 gluon/main.py
--- a/gluon/main.py	Thu Feb 16 10:31:35 2012 +0100
+++ b/gluon/main.py	Thu Feb 16 10:36:42 2012 +0100
@@ -355,6 +355,7 @@
         try:
             try:
                 # ##################################################
+                # handle uWSGI incorrect/missing environ vars
                 # handle fcgi missing path_info and query_string
                 # select rewrite parameters
                 # rewrite incoming URL
@@ -362,6 +363,21 @@
                 # parse rewritten URL
                 # serve file if static
                 # ##################################################
+		uwsgi = environ.get('uwsgi.version')
+		if uwsgi:
+		    uwsgi_version = []
+		    for x in uwsgi.split('.'):
+			for y in x.split('-'):
+			    if y == 'dev':
+				y = -1
+			    uwsgi_version.append(int(y))
+		if uwsgi and uwsgi_version < [1, 1, -1, 1996]:
+		    # handles uWSGI broken path_info AND missing QUERY_STRING
+		    environ['PATH_INFO'] = ''
+		if uwsgi and not environ.get('REMOTE_ADDR'):
+                    # REMOTE_ADDR is used for logging, which silently fails
+		    environ['REMOTE_ADDR'] = environ.get('HTTP_X_FORWARDED_FOR',
+		                                         'address.unknown')
 
                 if not environ.get('PATH_INFO',None) and \
                         environ.get('REQUEST_URI',None):

Reply via email to