5

I have one server that has several APIs running on it. One of them is users-DB The following gets down to gunicorn just fine:

location /usersDB/ {
    include proxy_params;
    proxy_pass http://unix:/home/ubuntu/projects/UsersDB-api/app.sock;
}

Except when I try to access the usersDB API's /helloWorld route, and look in the logs at gunicorn.err I see:

GET /usersDB/helloWorld

I was hoping to see:

GET /helloWorld

Of course, gunicorn returns 404s and that is what I see in my browser. I've tried rewrite rules:

location /usersDB/ {
    rewrite /usersDB/(.*) /$1 last;
    include proxy_params;
    proxy_pass http://unix:/home/ubuntu/projects/UsersDB-api/app.sock;
}

But the above results in the requests making their way to /var/www/htmlhelloWorld instead of app.sock.

I know that if you use a url for the proxy_pass you just add a trailing /, but I'm not sure what to do in the case of a sock file.

How do I get rid of the /usersDB/ suffix that is now included on all routes in nginx?

dim_voly
  • 478
  • 2
  • 10
  • 20
  • 1
    Also, your `rewrite` would work if you used `break`. See [this document](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite) for details. – Richard Smith Feb 13 '18 at 09:57

1 Answers1

13

Use a separating :. For example:

proxy_pass http://unix:/home/ubuntu/projects/UsersDB-api/app.sock:/;

See this document for details.

Richard Smith
  • 45,711
  • 6
  • 82
  • 81