{"id":23718382,"url":"https://github.com/jxnkwlp/nginxconfigparser","last_synced_at":"2025-04-19T21:38:38.896Z","repository":{"id":37308698,"uuid":"365665376","full_name":"jxnkwlp/NginxConfigParser","owner":"jxnkwlp","description":"A .net standard library for reading and writing nginx configuration files.","archived":false,"fork":false,"pushed_at":"2024-08-25T11:05:04.000Z","size":139,"stargazers_count":21,"open_issues_count":2,"forks_count":7,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-16T05:07:24.125Z","etag":null,"topics":["nginx","nginx-config-generate","nginx-configuration"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jxnkwlp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-09T04:18:53.000Z","updated_at":"2024-09-25T18:50:47.000Z","dependencies_parsed_at":"2024-02-13T06:29:57.376Z","dependency_job_id":"26c0728a-d089-4304-93d7-659ffe5e2e56","html_url":"https://github.com/jxnkwlp/NginxConfigParser","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxnkwlp%2FNginxConfigParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxnkwlp%2FNginxConfigParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxnkwlp%2FNginxConfigParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jxnkwlp%2FNginxConfigParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jxnkwlp","download_url":"https://codeload.github.com/jxnkwlp/NginxConfigParser/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249811714,"owners_count":21328845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nginx","nginx-config-generate","nginx-configuration"],"created_at":"2024-12-30T21:20:42.564Z","updated_at":"2025-04-19T21:38:38.877Z","avatar_url":"https://github.com/jxnkwlp.png","language":"C#","funding_links":["https://www.buymeacoffee.com/jxnkwlp"],"categories":[],"sub_categories":[],"readme":"﻿# NGINX configuration file parser and builder\n\nA .net standard library for reading and writing nginx configuration files.\n\n## Quick start\n\nInstall nuget package [![NuGet](https://img.shields.io/nuget/v/NginxConfigParser?style=flat-square)](https://www.nuget.org/packages/NginxConfigParser)\n\n### Create new file\n\n```cs\nNginxConfig.Create()\n    .AddOrUpdate(\"http:server:listen\", \"80\")\n    .AddOrUpdate(\"http:server:root\", \"/var/wwwroot\")\n    // add location\n    .AddOrUpdate(\"http:server:location\", \"/\", true, \"default\")\n    .AddOrUpdate(\"http:server:location:root\", \"/app1\")\n    // add location\n    .AddOrUpdate(\"http:server:location[1]\", \"~ ^/(images|javascript|js|css|flash|media|static)/\", true)\n    .AddOrUpdate(\"http:server:location[1]:root\", \"/app2\")\n    .AddOrUpdate(\"http:server:location[1]:expires\", \"1d\")\n    // add location\n    .AddOrUpdate(\"http:server:location[2]\", \"~/api\", true, \"api\")\n    .AddOrUpdate(\"http:server:location[2]:proxy_pass\", \"http://server.com\")\n    // save file\n    .Save(\"temp2.conf\");\n```\n\nThe `temp2.conf` file content ：\n\n```\nhttp   {\n\n  server   {\n    listen  80;\n    root  /var/wwwroot;\n\n    location  / { # default\n      root  /app1;\n    }\n\n    location  ~ ^/(images|javascript|js|css|flash|media|static)/ {\n      root  /app2;\n      expires  1d;\n    }\n\n    location  ~/api { # api\n      proxy_pass  http://server.com;\n    }\n\n  }\n}\n\n```\n\n### Read exist file\n\n```cs\n// load from file\nvar config = NginxConfig.LoadFrom(\"nginx.conf\");\n\n// read single value\nConsole.WriteLine(config.GetToken(\"worker_processes\")); // read the root key 'worker_processes'\nConsole.WriteLine(config[\"http:log_format\"])); // read the key 'log_format' from http section\nConsole.WriteLine(config[\"http:server[2]:root\"])); // read the key 'root' from second http server\n\n// read multi values\n// read all values by key 'include' from http section\nconfig.GetTokens(\"http:include\").ToList().ForEach(item =\u003e\n{\n    Console.WriteLine(item);\n});\n\n// read all group section\nConsole.WriteLine(config.GetGroup(\"http\"));  // get all from group key 'http'\n\n// add or update value\nconfig.AddOrUpdate(\"http:root\", \"/var/wwwroot\");\nconfig.AddOrUpdate(\"http:server:root\", \"/var/wwwroot/server1\");\nconfig.AddOrUpdate(\"http:server[2]:root\", \"/var/wwwroot/server2\");\n\n// add group\nconfig.AddOrUpdate(\"http:server:location\", \"/api\", true, comment: \"new location\");\n// add value to group\nconfig.AddOrUpdate(\"http:server:location:root\", \"/var/wwwroot/api\");\nConsole.WriteLine(config[\"http:server:location:root\"]);\n\n// delete value\nconfig.Remove(\"http:server:access_log\"); // remove by key\nconfig.Remove(\"http:server:location\"); // remove the location section\n\n// save to file\nconfig.Save(\"nginx.conf\");\n// or get file content\nstring configContent = config.ToString();\n\n```\n\n## Buy Me A Coffee\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jxnkwlp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxnkwlp%2Fnginxconfigparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjxnkwlp%2Fnginxconfigparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjxnkwlp%2Fnginxconfigparser/lists"}