# nginxparser
**Repository Path**: cuihui2012/nginxparser
## Basic Information
- **Project Name**: nginxparser
- **Description**: 基于原作者0.9.3版本,二次开发1.0.0版本
原作者:https://github.com/odiszapc/nginx-java-parser.git
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2021-09-15
- **Last Updated**: 2024-11-22
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Nginx configuration Java parser
This library helps in analyzing Nginx web server configuration files, looking up for specified parameters, blocks, regular expressions or comments. Then AST can be modified and converted back to plain file.
#### Features
- Convert config file to AST tree using ANTLR4 parsing capabilities
- The same is available for JavaCC too (deprecated)
- Rebuild config files and dump them back to *.conf
- Nested blocks support
- If statements support
- Unquoted regexp within location/rewrite/if statements support
- Comments support
#### Installation
Add the following dependency to your POM:
```xml
com.github.odiszapc
nginxparser
0.9.2
```
#### Examples
##### Parser
How to perform basic parsing of the following Nginx config:
```java
NgxConfig conf = NgxConfig.read("/etc/nginx/nginx.conf");
NgxParam workers = conf.findParam("worker_processes"); // Ex.1
workers.getValue(); // "1"
NgxParam listen = conf.findParam("http", "server", "listen"); // Ex.2
listen.getValue(); // "8889"
List rtmpServers = conf.findAll(NgxConfig.BLOCK, "rtmp", "server"); // Ex.3
for (NgxEntry entry : rtmpServers) {
((NgxBlock)entry).getName(); // "server"
((NgxBlock)entry).findParam("application", "live"); // "on" for the first iter, "off" for the second one
}
```
/etc/nginx/nginx.conf:
```
worker_processes 1; # <- Ex.1
http {
server {
listen 8889; # <- Ex.2
server_name localhost;
}
}
rtmp {
server { # <- Ex.3 (first)
listen 1935;
application myapp {
live on;
}
}
server { # <- Ex.3 (second)
listen 1936;
application myapp2 {
live off;
}
}
}
```
##### Dumper
```java
NgxConfig conf = NgxConfig.read("/etc/nginx/nginx.conf");
// ...
NgxDumper dumper = new NgxDumper(conf);
return dumper.dump(System.out);
```
#### Authors
Alexey Plotnik (odiszapc@gmail.com, http://twitter.com/odiszapc) I do it just because I like it.
#### Nginx RTMP reporting
This library was developed as part of WMSPanel (https://wmspanel.com/) integration with **nginx-rtmp-module**. WMSPanel is a cloud control and reporting panel for multiple media servers, so now it supports Nginx as well. Please check https://wmspanel.com/nginx for details.
#### License
Apache 2.0