I'm at a loss even as to where the problem lies, so I'll give you the full background.
I set up a django app on my Linux server, with nginx and gunicorn, and started with a toy example.
Here's urls.py
:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^(.*)/', views.helloworld),
url(r'^$', views.homepage),
]
And here's views.py
:
from django.shortcuts import render
from django.http import HttpResponse
def helloworld(request, string):
return HttpResponse("Hello World! " + string)
def homepage(request):
return HttpResponse("Homepage!")
For the app I'm working on it's imperative that I be able to handle non-ascii characters in the url, so I tested by visiting /é
. With ./manage.py runserver
, everything works as intended: I'm redirected to /é/
(with a trailing slash), and "Hello World! é" is printed back.
When I deploy it on the server, though, the behavior changes. If I visit /é/
, with the trailing slash, I get "Hello World! %C3%A9", without the percent encoding being decoded. Fine, I don't know why the behavior is different, but I can live with that.
If I visit /é
though, without the trailing slash, then as the trailing slash is added, I get redirected to /%25C3%25A9/
, with the percent signs themselves double encoded. I would like to avoid the %25
, but I don't know who's adding them, or how to disable it.
Help please?
If helpful, here's the nginx config (relevant part):
upstream app_server_2 {
server 127.0.0.1:7000 fail_timeout=0;
}
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
index index.html index.htm;
[...]
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server_2;
}
}