Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect/rewrite nginx location to .sock file without prefix

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?

like image 833
dim_voly Avatar asked Dec 13 '22 18:12

dim_voly


1 Answers

Use a separating :. For example:

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

See this document for details.

like image 166
Richard Smith Avatar answered Feb 23 '23 10:02

Richard Smith