nginx rewrite 正则表达式

http://localhost/action
http://localhost/action/pre/xx/xx

所有action接口交给tomcat处理, 但为了能同时访问上面的两个URL, 我配置了下面两个location段, 总觉得这种配置方式不是很优雅, 请教大神有什么更好的方法, 不甚感激!

location ~ ^/(action)/?$ {
    proxy_pass  http://tomcats;
}

location ~ ^/(action)/(.+)$ {
    proxy_pass  http://tomcats;
}
阅读 3.1k
1 个回答

看你的需要求,直接

location ^~ /action/{
    proxy_pass  http://tomcats;
}

应该就行了。