Crates.io | webserver-config |
lib.rs | webserver-config |
version | 0.1.1 |
source | src |
created_at | 2024-07-26 20:31:56.451083 |
updated_at | 2024-08-14 10:46:15.764184 |
description | A Rust crate for generating configuration files for web servers. |
homepage | |
repository | https://git.codespace.cz/oohost/webserver-config |
max_upload_size | |
id | 1316745 |
size | 8,824 |
A Rust crate for generating configuration files for web servers. Supported web servers include Apache2 and nginx.
Add this crate to your Cargo.toml
or use the command bellow:
cargo add webserver-config
Below are examples of using the crate to generate configurations for Apache2 and nginx web servers.
Here's how you can generate a configuration for Apache2 web server:
let mut config = Config::new();
let mut block = Block::new("VirtualHost", "*:80");
block.modify_config(|c| {
c.add("ServerName", "example.com");
c.add_multi("ServerAlias", vec!["www.example.com", "example.net", "www.example.net"]);
c.add("DocumentRoot", "/var/www/example");
});
config.add_block(block);
println!("{}", config.to_apache());
The code above will produce the following output:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com example.net www.example.net
DocumentRoot /var/www/example
</VirtualHost>
Here's how you can generate a configuration for nginx web server:
let mut config = Config::new();
let mut block = Block::new_simple("server");
block.modify_config(|c| {
c.add("listen", "80");
c.add("listen", "[::]:80");
c.add_multi("server_name", vec!["example.com", "www.example.com"]);
c.add("root", "/var/www/example");
});
config.add_block(block);
println!("{}", config.to_nginx());
The code above will produce the following output:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example;
}
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.