Quantcast
Channel: Code Painters » webapps
Viewing all articles
Browse latest Browse all 5

WSGI deployment under a subpath using uWSGI and Nginx

$
0
0

It's relatively obvious how to deploy a WSGI application using Nginx, and there are many tutorials out there dealing with this very task. It took me quite a few minutes, however, to figure out how to deploy the application under non-root URL, e.g. http://some.site.com/admin/.

This is typically dealt with by configuring the SCRIPT_NAME CGI parameter, and letting this name be removed from the beginning of the PATH_INFO parameter by the WSGI environment, before the path is passed down to the application. This way the WSGI application routing remains the same, no matter where in the URL tree it is deployed. The application needs to be aware of SCRIPT_NAME parameter only to generate proper URLs to self.

It turned out that Nginx configuration need to contain magical uwsgi_parameter1 30; setting, e.g.:

server {
    // ...
    location /admin/ {
        uwsgi_pass unix:/path/to/uwsgi.socket;
        include uwsgi_params;
        uwsgi_param SCRIPT_NAME /admin;
        uwsgi_modifier1 30;
    }
}

The uwsgi_modifier1 parameter is listed in the Nginx's uWSGI module documentation, but it doesn't really explain what modifier1 is? Why it needs to be 30? The answer can be found in the uWSGI protocol documentation. The modifier1 is simply used to denote the uWSGI protocol's packet type. According to the table, value 30 means:

Standard WSGI request followed by the HTTP request body. The PATH_INFO is automatically modified, removing the SCRIPT_NAME from it.

Packets of type 0 (default) and 30 differ only in how SCRIPT_INFO is handled. I really wish there was a better documentation for this kind of feature. The parameter names used don't help googling, either...


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images