nginx - 使用 nginx 将所有请求重定向到 api 服务器

标签 nginx

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

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

这是我写的规则

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

但它不起作用。有什么想法吗?

最佳答案

尝试

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

proxy_pass 指令中,如果您指定的 URI 为 /api/v1/ (在您的情况下),所有匹配的 URI 将被替换为确切指定的 >/api/v1/ 但不是 /api/v1/*

关于nginx - 使用 nginx 将所有请求重定向到 api 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558204/

相关文章:

wordpress - 如何在域的子目录中配置wordpress,而主目录包含nextjs项目?(EC2,Ubuntu20,Nginx服务器)

linux - nginx force SSL no-www 重定向问题

model-view-controller - MVC 作为客户端的 Nginx 配置

django - 通过 Nginx 和 SEO 优化提供不会过期的内容

php - Varnish+Nginx+Magento 无法多次提供同一页面,resp 502

java - 从 spring 重定向 url 中删除项目名称前缀

ssl - 间歇性 SSL 握手错误 nginx

ssl - NGINX:基于具有不同端口的本地主机上多个应用程序路径的 ssl 代理

ssl - 如何正确代理 https 流量?

python - 如何使用 nginx 和 uwsgi 从子目录中提供 Flask 应用程序