如何编写用于替换查询字符串中的查询参数的 nginx 重写规则
How to write nginx rewrite rule for replacing query param in query string
伙计们!
我们有以下 http 请求:
我们想将 redirect_uri
从 "some.domain.com" 替换为 "other.domain.com"。
怎么做?
谢谢
你需要这样做
location /auth/realms/master-realm/protocol/openid-connect/auth {
if ($args ~* "(.*)(some\.domain\.com)(.*)") {
set $args "other.domain.com";
return 301 $scheme://$host$uri$args;
}
}
测试:
curl -I "vm/auth/realms/master-realm/protocol/openid-connect/auth?response_type=code&client_id=regportal&redirect_uri=http%3A%2F%2Fsome.domain.com%2Fregportal%2Fsso%2Flogin&state=a49a02d5-f873-453f-9148-61793f11ecf3&login=true&scope=openid"
HTTP/1.1 301 Moved Permanently
Server: openresty/1.11.2.2
Date: Fri, 15 Sep 2017 06:01:51 GMT
Content-Type: text/html
Content-Length: 191
Connection: keep-alive
Location: http://vm/auth/realms/master-realm/protocol/openid-connect/authresponse_type=code&client_id=regportal&redirect_uri=http%3A%2F%2Fother.domain.com%2Fregportal%2Fsso%2Flogin&state=a49a02d5-f873-453f-9148-61793f11ecf3&login=true&scope=openid
伙计们!
我们有以下 http 请求:
我们想将 redirect_uri
从 "some.domain.com" 替换为 "other.domain.com"。
怎么做?
谢谢
你需要这样做
location /auth/realms/master-realm/protocol/openid-connect/auth {
if ($args ~* "(.*)(some\.domain\.com)(.*)") {
set $args "other.domain.com";
return 301 $scheme://$host$uri$args;
}
}
测试:
curl -I "vm/auth/realms/master-realm/protocol/openid-connect/auth?response_type=code&client_id=regportal&redirect_uri=http%3A%2F%2Fsome.domain.com%2Fregportal%2Fsso%2Flogin&state=a49a02d5-f873-453f-9148-61793f11ecf3&login=true&scope=openid"
HTTP/1.1 301 Moved Permanently
Server: openresty/1.11.2.2
Date: Fri, 15 Sep 2017 06:01:51 GMT
Content-Type: text/html
Content-Length: 191
Connection: keep-alive
Location: http://vm/auth/realms/master-realm/protocol/openid-connect/authresponse_type=code&client_id=regportal&redirect_uri=http%3A%2F%2Fother.domain.com%2Fregportal%2Fsso%2Flogin&state=a49a02d5-f873-453f-9148-61793f11ecf3&login=true&scope=openid