Nginx proxy_pass部分url和params

nwnhqdif  于 2023-04-05  发布在  Nginx
关注(0)|答案(1)|浏览(167)

我需要代理请求从我的服务器到另一个两个选项应该实现
第一:
https://my-site.com/subjects/custom_idhttps://another-site.com/subjects/custom_id
示例:
https://my-site.com/subjects/1https://another-site.com/subjects/1
https://my-site.com/subjects/2https://another-site.com/subjects/2
Nginx配置(工作正常):

location ~ ^/subjects/?(.*) {
     resolver 8.8.8.8;
     proxy_pass https://another-site.com/subjects/$1$is_args$args;
   }

第二:
https://my-site.com/subjects?code=custom_codehttps://another-site.com/subjects?code=custom_code
示例:
https://my-site.com/subjects?code=1https://another-site.com/subjects?code=1
https://my-site.com/subjects?code=2https://another-site.com/subjects?code=2
如何为这种情况编写Nginx配置?

lokaqttq

lokaqttq1#

固定:

location ^~ /subjects {
     resolver 8.8.8.8;
     proxy_pass https://another-site.com/subjects;
}

相关问题