Redirect/rewrite nginx 位置到 .sock 文件没有前缀

Redirect/rewrite nginx location to .sock file without prefix

我有一台服务器,上面有几个 APIs 运行。其中之一是 users-DB 下面是 gunicorn 就好了:

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

除非我尝试访问 usersDB API 的 /helloWorld 路由,并查看 gunicorn.err 的日志,我看到:

GET /usersDB/helloWorld

我希望看到:

GET /helloWorld

当然,gunicorn returns 404s,这就是我在浏览器中看到的。我试过重写规则:

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

但上述结果导致请求进入 /var/www/htmlhelloWorld 而不是 app.sock。

我知道如果你对 proxy_pass 使用 url,你只需添加一个 trailing /,但我不确定在 sock 文件的情况下该怎么做.

如何去掉现在包含在 nginx 所有路由中的 /usersDB/ 后缀?

使用分隔符:。例如:

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

详情见this document