【发布时间】: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