Nginx, Bad Request and percent in URL

nginx

I have an url like this: "mydomain.com/dictionary/Elastizit%E4t.htm".

I know the url sucks, I'm migrating a very old site and for SEO reasons we need to make redirects from the old urls to the new ones. So for the time being I have something like 14000 URLs like this and I need to redirect them to their new companions or follow some redirect rules defined in my django/python webserver.

If the URL would hit my python app, I'd be able to handle it like this:

>>> from urllib.parse import unquote
>>> unquote('Elastizit%E4t.htm', encoding='latin')
'Elastizität.htm'

However, nginx itself breaks with a 400 Bad Request.

My Nginx config is very simple:

server {
    listen 80;
    server_name mydomain.com;
    client_max_body_size 10M;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /srv/mydomain.com/shared/public;
    }

    location / {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/.htpasswd;

        include proxy_params;
        proxy_pass http://unix:/srv/mydomain.com/current/gunicorn.sock;
    }
}

It's important to me, that the webserver itself utf-8, I don't want to have iso-8859-1 and friends as my default encoding.

Best Answer

It turned out to be a bug in most python frameworks, aka https://code.djangoproject.com/ticket/25623 and https://github.com/Pylons/pyramid/issues/2047.