近期项目nginx负载均衡,需要对nginx的配置文件nginx.conf中的Listener和Member进行增删改的操作。找到了一个神器完美的解决了对配置文件的操作,并且以后写其他文件时也可以使用。
1,可以在github上找到nginx-java-parser工具,项目地址:https://github.com/odiszapc/nginx-java-parser, 解析nginx.conf过程可以参考该项目的README.md
2,更简便的方法是此工具在maven仓库中有依赖,可以直接把依赖引用的项目中
<!-- https://mvnrepository.com/artifact/com.github.odiszapc/nginxparser -->
<dependency>
<groupId>com.github.odiszapc</groupId>
<artifactId>nginxparser</artifactId>
<version>0.9.3</version>
</dependency>
以下详细说明此依赖如何使用
http {
server {
listen 80;
server_name www.nginx.cn;
location / {
proxy_pass http://www.nginx.cn;
proxy_set_header Host $host;
proxy_set_hea