PHPackages                             madkom/nginx-configurator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. madkom/nginx-configurator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

madkom/nginx-configurator
=========================

1.0.0-RC1(10y ago)3693110[1 issues](https://github.com/madkom/nginx-configurator/issues)MITPHP

Since Jun 10Pushed 4y ago5 watchersCompare

[ Source](https://github.com/madkom/nginx-configurator)[ Packagist](https://packagist.org/packages/madkom/nginx-configurator)[ Docs](http://madkom.pl/)[ RSS](/packages/madkom-nginx-configurator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

NGINX Configurator
==================

[](#nginx-configurator)

PHP Library for NGINX configuration parser/generator

[![PHP 7.0](https://camo.githubusercontent.com/60f2b2577187e1ceca976d6a9f7a457c657b20dbf85d7a76a3ac28e32e740eb6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d3843394342362e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/60f2b2577187e1ceca976d6a9f7a457c657b20dbf85d7a76a3ac28e32e740eb6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e302d3843394342362e7376673f7374796c653d666c6174)[![Build Status](https://camo.githubusercontent.com/38d170cf5f5ce2d8d7903f4dc0ac2ea71f0a893155cb4a45f4c574c4fc73d4e7/68747470733a2f2f7472617669732d63692e6f72672f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/madkom/nginx-configurator)[![Latest Stable Version](https://camo.githubusercontent.com/e17739d79046c337608deb148caf20ba77fa637728b108d6268d754391229ec5/68747470733a2f2f706f7365722e707567782e6f72672f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f762f737461626c65)](https://packagist.org/packages/madkom/nginx-configurator)[![Total Downloads](https://camo.githubusercontent.com/ce9530a3a416b64949a8ca24295eaaa725abc7d8a6a079a7952f7daae16749d1/68747470733a2f2f706f7365722e707567782e6f72672f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f646f776e6c6f616473)](https://packagist.org/packages/madkom/nginx-configurator)[![License](https://camo.githubusercontent.com/cd6d79451911b03cb5c21d919f28145162048ed8cc2f5dc1617a38266b5333d0/68747470733a2f2f706f7365722e707567782e6f72672f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f6c6963656e7365)](https://packagist.org/packages/madkom/nginx-configurator)[![Coverage Status](https://camo.githubusercontent.com/81091df58f0432a1c2b41b82d96350e3a82c1a7efec64cb887c6000e0ab01b73/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/madkom/nginx-configurator?branch=master)[![Code Climate](https://camo.githubusercontent.com/62e658dcb16b525b2a03153130e9286b8239a323e67562d55d38e58da1a0b76c/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f6261646765732f6770612e737667)](https://codeclimate.com/github/madkom/nginx-configurator)[![Issue Count](https://camo.githubusercontent.com/75fa38a795de1d29e2184a8a7991ef4c85b64efd73f82781eca2863d28288341/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d61646b6f6d2f6e67696e782d636f6e666967757261746f722f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/madkom/nginx-configurator)

---

Features
--------

[](#features)

This library can parse and generate NGINX configuration files. In near future will provide CLI commands for NGINX configuration.

Installation
------------

[](#installation)

Install with Composer

```
composer require madkom/nginx-configurator

```

Requirements
------------

[](#requirements)

This library requires *PHP* in `~7` version.

Usage
-----

[](#usage)

Parsing configuration string:

```
use Madkom\NginxConfigurator\Builder;
use Madkom\NginxConfigurator\Config\Server;
use Madkom\NginxConfigurator\Parser;

require 'vendor/autoload.php';

$config =  0) {
    /** @var Server $defaultServer */
    foreach ($defaultServers as $defaultServer) {
        $builder->append($defaultServer);
    }
}
```

Generating configuration string:

```
use Madkom\NginxConfigurator\Factory;
use Madkom\NginxConfigurator\Builder;
use Madkom\NginxConfigurator\Config\Location;
use Madkom\NginxConfigurator\Node\Directive;
use Madkom\NginxConfigurator\Node\Literal;
use Madkom\NginxConfigurator\Node\Param;

require __DIR__ . '/../vendor/autoload.php';

$factory = new Factory()
$builder = new Builder();

$server = $builder->append($factory->createServer(80));
$server->append(new Directive('error_log', [
    new Param('/var/log/nginx/error.log'),
    new Param('debug'),
]));
$server->append(new Location(new Param('/test'), null, [
    new Directive('error_page', [new Param('401'), new Param('@unauthorized')]),
    new Directive('set', [new Param('$auth_user'), new Literal('none')]),
    new Directive('auth_request', [new Param('/auth')]),
    new Directive('proxy_pass', [new Param('http://test-service')]),
]));
$server->append(new Location(new Param('/auth'), null, [
    new Directive('proxy_pass', [new Param('http://auth-service:9999')]),
    new Directive('proxy_bind', [new Param('$server_addr')]),
    new Directive('proxy_redirect', [new Param('http://$host'), new Param('https://$host')]),
    new Directive('proxy_set_header', [new Param('Content-Length'), new Literal("")]),
    new Directive('proxy_pass_request_body', [new Param('off')]),
]));
$server->append(new Location(new Param('@unauthorized'), null, [
    new Directive('return', [new Param('302'), new Param('/login?backurl=$request_uri')]),
]));
$server->append(new Location(new Param('/login'), null, [
    new Directive('expires', [new Param('-1')]),
    new Directive('proxy_pass', [new Param('http://identity-provider-service')]),
    new Directive('proxy_bind', [new Param('$server_addr')]),
    new Directive('proxy_redirect', [new Param('http://$host'), new Param('https://$host')]),
    new Directive('proxy_set_header', [new Param('Content-Length'), new Literal("")]),
    new Directive('proxy_pass_request_body', [new Param('off')]),
]));

print($builder->dump());
```

Generated configuration output:

```
server {
        listen 80;
        listen [::]:80 default ipv6only=on;
        error_log /var/log/nginx/error.log debug;
        location  /test {
                error_page 401 @unauthorized;
                set $auth_user "none";
                auth_request /auth;
                proxy_pass http://test-service;
        }

        location  /auth {
                proxy_pass http://auth-service:9999;
                proxy_bind $server_addr;
                proxy_redirect http://$host https://$host;
                proxy_set_header Content-Length "";
                proxy_pass_request_body off;
        }

        location  @unauthorized {
                return 302 /login?backurl=$request_uri;
        }

        location  /login {
                expires -1;
                proxy_pass http://identity-provider-service;
                proxy_bind $server_addr;
                proxy_redirect http://$host https://$host;
                proxy_set_header Content-Length "";
                proxy_pass_request_body off;
        }

}

```

There are also methods to read and dump file:

```
use Madkom\NginxConfigurator\Builder;
use Madkom\NginxConfigurator\Config\Location;
use Madkom\NginxConfigurator\Config\Server;
use Madkom\NginxConfigurator\Node\Directive;
use Madkom\NginxConfigurator\Node\Literal;
use Madkom\NginxConfigurator\Parser;

require __DIR__ . '/../vendor/autoload.php';

$parser = new Parser();
$builder = new Builder();

$configuration = $parser->parseFile('default.conf');

/** @var Server $servers[] */
$servers = $configuration->search(function (Node $node) {
    return $node instanceof Server;
});
if (count($servers) > 0) {
    /** @var Server $server */
    foreach ($servers as $server) {
        $builder->append($server);
    }
}

$builder->dumpFile('generated.conf');
```

TODO
----

[](#todo)

- Implement comments parsing
- Implement commands for config manipulation from CLI

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2016 Madkom S.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3668d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/406fcac8020975863dc6ca1f7cf729eb9755911131bce696ba502218c0536be5?d=identicon)[Madkom](/maintainers/Madkom)

---

Top Contributors

[![brzuchal](https://avatars.githubusercontent.com/u/3149753?v=4)](https://github.com/brzuchal "brzuchal (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/madkom-nginx-configurator/health.svg)

```
[![Health](https://phpackages.com/badges/madkom-nginx-configurator/health.svg)](https://phpackages.com/packages/madkom-nginx-configurator)
```

###  Alternatives

[rumenx/php-seo

AI-powered, framework-agnostic PHP package for automated SEO optimization. Intelligently generates meta tags, titles, descriptions, and alt texts using configurable AI providers or manual patterns.

103.7k](/packages/rumenx-php-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
