-1

A web-application setup using a CouchDB database is giving me a headache. The issue seems to be, that the document ID's contain special characters as "/", "-" or spaces. Here is an example URL (encoded)

http://127.0.0.1:5984/procedures/1%2F1%2F1143%2F1%2Fschwer%2F1%2F0.0%2F1.3

The CouchDB is configured with nginx as a reverse proxy, so http://127.0.0.1:5984/ is available at https://example.com/db

The problem now is that when using standard procedures, nginx seems to decode the URL during a rewrite, but then not encode it again.

We have come up with the following location setup in nginx to overcome the issue:

location /db {
  set $modified_uri $request_uri;

  if ($modified_uri ~ "^(.{3})(.*)") {
    set $modified_uri $2;
  }
  proxy_pass http://127.0.0.1:5984$modified_uri;
}

However now, a slash "/" is encoded with '%252F' instead of '%2F'. Does anyone have an idea on how to fix this issue? Thanks a lot!

Christoph Pahmeyer
  • 513
  • 1
  • 5
  • 17
  • Try using `$uri` instead of `$request_uri`. – Richard Smith Aug 02 '17 at 18:01
  • Thanks a lot for you comment! However, we could unfortunately not use the $uri variable as it strips the requests params from the original request. What worked (and eventually solved our issue) however was the following [post](https://stackoverflow.com/a/34290612). Hope someone else encountering these issues will benefit from that post, too! – Christoph Pahmeyer Aug 03 '17 at 15:24

1 Answers1

1

Use regex to capture the uri and then set directive to keep the encoding intact.

location  ~ ^/db(.*)$ {
  set $query $1;
  proxy_pass http://127.0.0.1:5984$query;
}
Manojkumar Khotele
  • 963
  • 11
  • 25