使用Nginx将所有请求重定向到api服务器 [英] redirect all the requests to api server with nginx

查看:1155
本文介绍了使用Nginx将所有请求重定向到api服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Nginx作为反向代理来将api请求重定向到我的服务器.不幸的是,它无法正常工作

I'm using Nginx as a reverse proxy to redirect api request to one my server. Unfortunately it is not working properly

我想要实现的是将所有请求(例如/api/v1/*代理到http://my-api-server/api/v1/*

what I'm trying to achieve is to proxy all requests like /api/v1/* to http://my-api-server/api/v1/*

这是我写的规则

location /api/v1/ {
   proxy_pass http://my-api-server/api/v1/
}

但是它不起作用.有什么主意吗?

but it doesn't work. any idea?

推荐答案

尝试

location /api/v1/ {
   proxy_pass http://my-api-server
}

proxy_pass指令中,如果您指定的URI为/api/v1/,则所有匹配的URI将被替换为精确指定的一个/api/v1/,而不是/api/v1/*.

In proxy_pass directive, if you specify the URI which is /api/v1/ in your case, all matched URIs will be replaced as the exactly specified one /api/v1/ but not /api/v1/*.

这篇关于使用Nginx将所有请求重定向到api服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆