【问题标题】:Redirect/rewrite nginx location to .sock file without prefix将 nginx 位置重定向/重写到 .sock 文件,不带前缀
【发布时间】:2018-07-23 08:48:15
【问题描述】:

我有一台服务器,上面运行着多个 API。其中之一是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 返回 404,这就是我在浏览器中看到的。我试过重写规则:

location /usersDB/ {
    rewrite /usersDB/(.*) /$1 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/ 后缀?

【问题讨论】:

  • 另外,如果您使用 break,您的 rewrite 也可以使用。详情请见this document

标签: sockets nginx reverse-proxy gunicorn


【解决方案1】:

使用分隔符:。例如:

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

详情请见this document

【讨论】:

    猜你喜欢
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 2013-08-20
    • 2011-01-26
    • 1970-01-01
    • 2019-06-16
    相关资源
    最近更新 更多