The `uwsgi_modifier1 30` directive does not remove SCRIPT_NAME from PATH_INFO as documented

This is my nginx virtual host configuration.

debian:~# cat /etc/nginx/sites-enabled/mybox server { listen 8080; root /www; index index.html index.htm; server_name mybox; location /foo { uwsgi_pass unix:/tmp/uwsgi.sock; include uwsgi_params; uwsgi_param SCRIPT_NAME /foo; uwsgi_modifier1 30; } } 

This is the source code of my WSGI application.

 debian:~# cat /www/app.py def application(environ, start_response): path_info = script_name = request_uri = None if 'PATH_INFO' in environ: path_info = environ['PATH_INFO'] if 'SCRIPT_NAME' in environ: script_name = environ['SCRIPT_NAME'] if 'REQUEST_URI' in environ: request_uri = environ['REQUEST_URI'] output = 'PATH_INFO: ' + repr(path_info) + '\n' + \ 'SCRIPT_NAME: ' + repr(script_name) + '\n' + \ 'REQUEST_URL: ' + repr(request_uri) + '\n' start_response('200 OK', [('Content-Type','text/plain')]) return [output.encode()] 

I serve the WSGI application with these two commands:

 service nginx restart uwsgi -s /tmp/uwsgi.sock -w app --chown-socket=www-data:www-data 

This is the result that I see when I try to visit my web application.

 debian:~# curl http://mybox:8080/foo/bar PATH_INFO: '/foo/bar' SCRIPT_NAME: '/foo' REQUEST_URL: '/foo/bar' 

Since I mentioned uwsgi_modifier1 30; in my nginx virtual host configuration, I expected PATH_INFO to be only '/bar' , as described in the following two URLs:

Quoting the corresponding part from the first article:

The parameter uwsgi_modifier1 30 sets the modifier uWSGI UWSGI_MODIFIER_MANAGE_PATH_INFO . This modifier for each request tells the uWSGI server to overwrite the value of PATH_INFO, removing SCRIPT_NAME from it.

Quoting the corresponding part from the second article:

A standard WSGI request followed by an HTTP request body. PATH_INFO automatically changes, removing SCRIPT_NAME from it.

But I see that my PATH_INFO remains untouched as '/foo/bar' . Part of SCRIPT_NAME, i.e. '/foo' , not removed from it. Why?

+8
python wsgi nginx uwsgi
source share
1 answer

After reading http://gh.codehum.com/unbit/uwsgi/pull/19, I realized that using uwsgi_modifier1 30; outdated.

So this is how I solved the problem.

First of all, I deleted the SCRIPT_NAME processing in nginx by deleting these two lines:

  uwsgi_param SCRIPT_NAME /foo; uwsgi_modifier1 30; 

The resulting nginx configuration looked like this:

 debian:~# cat /etc/nginx/sites-enabled/mybox server { listen 8080; root /www; index index.html index.htm; server_name mybox; location /foo { uwsgi_pass unix:/tmp/uwsgi.sock; include uwsgi_params; } } 

Then I restarted nginx and processed SCRIPT_NAME in uwsgi using the --mount and --manage-script-name parameters like this.

 service nginx restart uwsgi -s /tmp/uwsgi.sock -w app --chown-socket=www-data:www-data --manage-script-name --mount=/foo=/www/app.py 

Now I get the expected result.

 debian:~# curl http://mybox:8080/foo/bar PATH_INFO: '/bar' SCRIPT_NAME: '/foo' REQUEST_URL: '/foo/bar' 
+11
source share

All Articles