首页 > 解决方案 > URL的nginx位置proxy_pass

问题描述

在我的 nginx 配置中,我想代理传递以下 URL

来源网址:

http://1.1.1.1:8080/SOME-SERVICE/sub-path

代理路径:

http://2.2.2.2:1234/SOME-SERVICE/sub-path

SOME-SERVICE值将具有不同的值,例如:

http://1.1.1.1:8080/user-service/sub-path
http://1.1.1.1:8080/auth-service/sub-path

我应该如何编写位置路径模式以匹配通用SOME-SERVICE值并使用该值代理 URL?

谢谢

标签: nginxnginx-locationnginx-reverse-proxynginx-config

解决方案


尝试这个:

location /*-service/ { // your stuff goes here }

或者,如果您有服务名称列表

location /(user|auth)-service/ { // your stuff goes here }

推荐阅读