{"id":15020838,"url":"https://github.com/xgfone/ngconf","last_synced_at":"2025-10-26T11:31:26.874Z","repository":{"id":57533645,"uuid":"233061071","full_name":"xgfone/ngconf","owner":"xgfone","description":"A generic parser of the NGINX config format","archived":false,"fork":false,"pushed_at":"2021-04-29T12:50:25.000Z","size":12,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T18:56:56.315Z","etag":null,"topics":["conf","config","configuration","nginx","nginx-conf","nginx-configuration"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgfone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-10T14:12:52.000Z","updated_at":"2023-07-13T16:16:48.000Z","dependencies_parsed_at":"2022-09-26T18:21:06.028Z","dependency_job_id":null,"html_url":"https://github.com/xgfone/ngconf","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fngconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fngconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fngconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fngconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/ngconf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238319481,"owners_count":19452343,"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":["conf","config","configuration","nginx","nginx-conf","nginx-configuration"],"created_at":"2024-09-24T19:55:45.225Z","updated_at":"2025-10-26T11:31:26.547Z","avatar_url":"https://github.com/xgfone.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ngconf [![Build Status](https://travis-ci.org/xgfone/ngconf.svg?branch=master)](https://travis-ci.org/xgfone/ngconf) [![GoDoc](https://godoc.org/github.com/xgfone/ngconf?status.svg)](http://godoc.org/github.com/xgfone/ngconf) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/ngconf/master/LICENSE)\n\nThe package `ngconf` supplies a generic parser of the `NGINX` config format referring to the implementation [python-nginx](https://github.com/radiosilence/python-nginx), and supports Go `1.x`.\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/xgfone/ngconf\"\n)\n\nconst conf = `\nuser www-data;\nworker_processes auto;\npid /run/nginx.pid;\ninclude /etc/nginx/modules-enabled/*.conf;\n\nevents {\n\tworker_connections 768;\n\t# multi_accept on;\n}\n\nstream {\n\tserver {\n\t\tlisten 127.0.0.1:8443;\n\t\tproxy_connect_timeout 1s;\n\t\tproxy_pass backend;\n\t}\n}\n\n\nhttp {\n\n\t##\n\t# Basic Settings\n\t##\n\n\tsendfile on;\n\ttcp_nopush on;\n\ttcp_nodelay on;\n\tkeepalive_timeout 65;\n\ttypes_hash_max_size 2048;\n\t# server_tokens off;\n\n\t# server_names_hash_bucket_size 64;\n\t# server_name_in_redirect off;\n\n\tinclude /etc/nginx/mime.types;\n\tdefault_type application/octet-stream;\n\n\t##\n\t# SSL Settings\n\t##\n\n\t# Dropping SSLv3, ref: POODLE\n\tssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n\tssl_prefer_server_ciphers on;\n\n\t##\n\t# Logging Settings\n\t##\n\n\taccess_log /var/log/nginx/access.log;\n\terror_log /var/log/nginx/error.log;\n\n\t##\n\t# Gzip Settings\n\t##\n\n\tgzip on;\n\n\t# gzip_vary on;\n\t# gzip_proxied any;\n\t# gzip_comp_level 6;\n\t# gzip_buffers 16 8k;\n\t# gzip_http_version 1.1;\n\t# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;\n\n\t##\n\t# Virtual Host Configs\n\t##\n\n\tinclude /etc/nginx/conf.d/*.conf;\n\tinclude /etc/nginx/sites-enabled/*;\n}\n\n#mail {\n#       # See sample authentication script at:\n#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript\n#\n#       # auth_http localhost/auth.php;\n#       # pop3_capabilities \"TOP\" \"USER\";\n#       # imap_capabilities \"IMAP4rev1\" \"UIDPLUS\";\n#\n#       server {\n#               listen     localhost:110;\n#               protocol   pop3;\n#               proxy      on;\n#       }\n#\n#       server {\n#               listen     localhost:143;\n#               protocol   imap;\n#               proxy      on;\n#       }\n#}`\n\nfunc main() {\n\troot, err := ngconf.Decode(conf)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n\n\t// Remove a config block.\n\troot.Del(\"events\")\n\n\t// Add a new config item.\n\tstream := root.Get(\"stream\")[0]\n\tbackend := stream.Add(\"upstream\", \"backend\")\n\tbackend.Add(\"hash\", \"$remote_addr\", \"consistent\")\n\tbackend.Add(\"server\", \"backend1:443\", \"max_fails=3\", \"fail_timeout=30s\")\n\n\t// // Get a config item.\n\tbackend = stream.Get(\"upstream\", \"backend\")[0]\n\thash := backend.Get(\"hash\", \"$remote_addr\")\n\tfmt.Println(len(hash), \"node:\", hash[0].Directive, hash[0].Args)\n\n\t// Print the whole config.\n\tfmt.Println(\"========================= Config =========================\")\n\tfmt.Println(root)\n\n\t/// Output:\n\t//\n\t// 1 node: hash [$remote_addr consistent]\n\t// ========================= Config =========================\n\t// user www-data;\n\t// worker_processes auto;\n\t// pid /run/nginx.pid;\n\t// include /etc/nginx/modules-enabled/*.conf;\n\t//\n\t// stream {\n\t//     server {\n\t//         listen 127.0.0.1:8443;\n\t//         proxy_connect_timeout 1s;\n\t//         proxy_pass backend;\n\t//     }\n\t//\n\t//     upstream backend {\n\t//         hash $remote_addr consistent;\n\t//         server backend1:443 max_fails=3 fail_timeout=30s;\n\t//     }\n\t// }\n\t//\n\t// http {\n\t//     ##\n\t//     # Basic Settings\n\t//     ##\n\t//     sendfile on;\n\t//     tcp_nopush on;\n\t//     tcp_nodelay on;\n\t//     keepalive_timeout 65;\n\t//     types_hash_max_size 2048;\n\t//\n\t//     # server_tokens off;\n\t//     # server_names_hash_bucket_size 64;\n\t//     # server_name_in_redirect off;\n\t//     include /etc/nginx/mime.types;\n\t//     default_type application/octet-stream;\n\t//\n\t//     ##\n\t//     # SSL Settings\n\t//     ##\n\t//     # Dropping SSLv3, ref: POODLE\n\t//     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n\t//     ssl_prefer_server_ciphers on;\n\t//\n\t//     ##\n\t//     # Logging Settings\n\t//     ##\n\t//     access_log /var/log/nginx/access.log;\n\t//     error_log /var/log/nginx/error.log;\n\t//\n\t//     ##\n\t//     # Gzip Settings\n\t//     ##\n\t//     gzip on;\n\t//\n\t//     # gzip_vary on;\n\t//     # gzip_proxied any;\n\t//     # gzip_comp_level 6;\n\t//     # gzip_buffers 16 8k;\n\t//     # gzip_http_version 1.1;\n\t//     # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;\n\t//     ##\n\t//     # Virtual Host Configs\n\t//     ##\n\t//     include /etc/nginx/conf.d/*.conf;\n\t//     include /etc/nginx/sites-enabled/*;\n\t// }\n\t//\n\t// #mail {\n\t// #       # See sample authentication script at:\n\t// #       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript\n\t// #\n\t// #       # auth_http localhost/auth.php;\n\t// #       # pop3_capabilities \"TOP\" \"USER\";\n\t// #       # imap_capabilities \"IMAP4rev1\" \"UIDPLUS\";\n\t// #\n\t// #       server {\n\t// #               listen     localhost:110;\n\t// #               protocol   pop3;\n\t// #               proxy      on;\n\t// #       }\n\t// #\n\t// #       server {\n\t// #               listen     localhost:143;\n\t// #               protocol   imap;\n\t// #               proxy      on;\n\t// #       }\n\t// #}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fngconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fngconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fngconf/lists"}