| Crates.io | nginx-discovery |
| lib.rs | nginx-discovery |
| version | 0.1.0 |
| created_at | 2026-01-22 07:27:39.61635+00 |
| updated_at | 2026-01-22 07:27:39.61635+00 |
| description | Discover and introspect NGINX configurations with ease |
| homepage | https://github.com/urwithajit9/nginx-discovery |
| repository | https://github.com/urwithajit9/nginx-discovery |
| max_upload_size | |
| id | 2060920 |
| size | 154,752 |
Discover and parse NGINX configurations with ease.
A Rust library for parsing, analyzing, and extracting information from NGINX configuration files. Perfect for building tools that need to understand NGINX configs programmatically.
Add to your Cargo.toml:
[dependencies]
nginx-discovery = "0.1"
use nginx_discovery::parse;
let config = r#"
server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
}
}
"#;
let parsed = parse(config)?;
println!("Found {} directives", parsed.directives.len());
use nginx_discovery::{parse, extract};
let config = parse(config_text)?;
let logs = extract::access_logs(&config)?;
for log in logs {
println!("Log: {}", log.path.display());
println!("Format: {:?}", log.format_name);
println!("Context: {:?}", log.context);
}
use nginx_discovery::{parse, extract};
let config = parse(config_text)?;
let formats = extract::log_formats(&config)?;
for format in formats {
println!("Format: {}", format.name());
println!("Variables: {:?}", format.variables());
}
Check out the examples/ directory:
lex_config.rs - Tokenize NGINX configsextract_logs.rs - Extract log configurationsRun an example:
cargo run --example extract_logs
The library is organized in layers:
βββββββββββββββββββββββββββββββββββββββ
β High-Level API (extract::*) β β Extract logs, servers, etc.
βββββββββββββββββββββββββββββββββββββββ€
β Parser (parse) β β Convert tokens to AST
βββββββββββββββββββββββββββββββββββββββ€
β Lexer (tokenize) β β Convert text to tokens
βββββββββββββββββββββββββββββββββββββββ€
β AST Types β β Type-safe representation
βββββββββββββββββββββββββββββββββββββββ
use nginx_discovery::parser::Lexer;
let mut lexer = Lexer::new("server { listen 80; }");
let tokens = lexer.tokenize()?;
use nginx_discovery::parse;
let config = parse("server { listen 80; }")?;
for directive in &config.directives {
println!("{}", directive.name());
}
use nginx_discovery::{parse, extract};
let config = parse(config_text)?;
let logs = extract::access_logs(&config)?;
The library has comprehensive test coverage:
# Run all tests
cargo test --all-features
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_name
[dependencies]
nginx-discovery = { version = "0.1", features = ["serde"] }
Available features:
serde - Serialize/deserialize AST typessystem (default) - System interaction utilitiesCurrently supports:
user nginx;server { ... }http { server { location { } } }"value" and 'value'$host, ${variable}80, 443, 1024# commentContributions are welcome! Please read CONTRIBUTING.md for details.
git clone https://github.com/urwithajit9/nginx-discovery.git
cd nginx-discovery
# Run tests
cargo test --all-features
# Run examples
cargo run --example extract_logs
# Format code
cargo fmt
# Run linter
cargo clippy --all-features -- -D warnings
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Built with β€οΈ in Rust.
Special thanks to the Rust community for excellent parser libraries and documentation.
Star β this repo if you find it useful!