![Nginx:位置正则表达式不起作用](https://linux22.com/image/655634/Nginx%EF%BC%9A%E4%BD%8D%E7%BD%AE%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我的正则表达式出了问题,不知道它出了什么问题。它返回的 URi 是orls/f
而不是orls/f?p=4550
。当我传递https://secure.toto02.com/orls/myservice/f?p=4550
我的配置文件如下
location ~ "^/([a-zA-Z]+)/myservice/(.+)$" {
error_log /var/log/nginx/error-server.log notice;
rewrite_log on;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://192.168.3.45:8080/orls/$2;
proxy_redirect http://192.168.3.45:8080/orls/ https://secure.toto02.com/$1/myservice/ ;
}
有人可以帮忙吗?
答案1
捕获位置不会包含查询字符串。您必须通过变量手动将其包含在内,$is_args
如下$args
所示:
proxy_pass http://192.168.3.45:8080/orls/$2$is_args$args;
参见@kolbyjack 的(更好的)答案:https://stackoverflow.com/questions/8130692/with-nginx-how-to-forward-query-parameters