NginxConfigParser 0.1.4

This package has a SemVer 2.0.0 package version: 0.1.4+56a7e6c2.
dotnet add package NginxConfigParser --version 0.1.4                
NuGet\Install-Package NginxConfigParser -Version 0.1.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NginxConfigParser" Version="0.1.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NginxConfigParser --version 0.1.4                
#r "nuget: NginxConfigParser, 0.1.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NginxConfigParser as a Cake Addin
#addin nuget:?package=NginxConfigParser&version=0.1.4

// Install NginxConfigParser as a Cake Tool
#tool nuget:?package=NginxConfigParser&version=0.1.4                

NGINX configuration file parser and builder

A .net standard library for reading and writing nginx configuration files.

Quick start

Install nuget package NuGet

Create new file

NginxConfig.Create()
    .AddOrUpdate("http:server:listen", "80")
    .AddOrUpdate("http:server:root", "/var/wwwroot")
    // add location
    .AddOrUpdate("http:server:location", "/", true, "default")
    .AddOrUpdate("http:server:location:root", "/app1")
    // add location
    .AddOrUpdate("http:server:location[1]", "~ ^/(images|javascript|js|css|flash|media|static)/", true)
    .AddOrUpdate("http:server:location[1]:root", "/app2")
    .AddOrUpdate("http:server:location[1]:expires", "1d")
    // add location
    .AddOrUpdate("http:server:location[2]", "~/api", true, "api")
    .AddOrUpdate("http:server:location[2]:proxy_pass", "http://server.com")
    // save file
    .Save("temp2.conf");

The temp2.conf file content :

http   {

  server   {
    listen  80;
    root  /var/wwwroot;

    location  / { # default
      root  /app1;
    }

    location  ~ ^/(images|javascript|js|css|flash|media|static)/ {
      root  /app2;
      expires  1d;
    }

    location  ~/api { # api
      proxy_pass  http://server.com;
    }

  }
}

Read exist file

// load from file
var config = NginxConfig.LoadFrom("nginx.conf");

// read single value
Console.WriteLine(config.GetToken("worker_processes")); // read the root key 'worker_processes'
Console.WriteLine(config["http:log_format"])); // read the key 'log_format' from http section
Console.WriteLine(config["http:server[2]:root"])); // read the key 'root' from second http server

// read multi values
// read all values by key 'include' from http section
config.GetTokens("http:include").ToList().ForEach(item =>
{
    Console.WriteLine(item);
});

// read all group section
Console.WriteLine(config.GetGroup("http"));  // get all from group key 'http'

// add or update value
config.AddOrUpdate("http:root", "/var/wwwroot");
config.AddOrUpdate("http:server:root", "/var/wwwroot/server1");
config.AddOrUpdate("http:server[2]:root", "/var/wwwroot/server2");

// add group
config.AddOrUpdate("http:server:location", "/api", true, comment: "new location");
// add value to group
config.AddOrUpdate("http:server:location:root", "/var/wwwroot/api");
Console.WriteLine(config["http:server:location:root"]);

// delete value
config.Remove("http:server:access_log"); // remove by key
config.Remove("http:server:location"); // remove the location section

// save to file
config.Save("nginx.conf");
// or get file content
string configContent = config.ToString();

Buy Me A Coffee

"Buy Me A Coffee"

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NginxConfigParser:

Package Downloads
NginxConfig

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.4 247 8/25/2024
0.1.3 18,538 5/12/2022
0.1.2 603 11/30/2021
0.1.1 419 6/12/2021
0.1.0 344 5/9/2021