PHPackages                             aleksey.nemiro/nginxconf.php - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. aleksey.nemiro/nginxconf.php

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

aleksey.nemiro/nginxconf.php
============================

Classes for working with configuration files of the Nginx.

1.0(10y ago)7774[1 issues](https://github.com/phperry/NginxConf.PHP/issues)Apache License 2.0PHPPHP &gt;=5.5,&gt;=7.0

Since Feb 21Pushed 10y ago1 watchersCompare

[ Source](https://github.com/phperry/NginxConf.PHP)[ Packagist](https://packagist.org/packages/aleksey.nemiro/nginxconf.php)[ Docs](https://github.com/alekseynemiro/NginxConf.PHP)[ RSS](/packages/alekseynemiro-nginxconfphp/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

### NginxConf.PHP [![Latest Stable Version](https://camo.githubusercontent.com/0dd4a093685c3bd37ec57d42d96f0dfd0cc25fe08873b5ab195b72b63794c52e/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f6e67696e78636f6e662e7068702f762f737461626c65)](https://packagist.org/packages/aleksey.nemiro/nginxconf.php) [![Total Downloads](https://camo.githubusercontent.com/0379ff71f585b64fe343dc9bc584b5ed2f9d3518a0e1c5574151578d37399bbf/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f6e67696e78636f6e662e7068702f646f776e6c6f616473)](https://packagist.org/packages/aleksey.nemiro/nginxconf.php) [![License](https://camo.githubusercontent.com/b849444487712343b255ca2c2f45eb03adba535830b6e6b2059d82d9ca438a70/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f6e67696e78636f6e662e7068702f6c6963656e7365)](https://packagist.org/packages/aleksey.nemiro/nginxconf.php)

[](#nginxconfphp---)

Classes for working with configuration files of the **Nginx** web server.

Code licensed under **Apache License Version 2.0**.

### Requirements

[](#requirements)

- PHP5 &gt;= 5.5, PHP7;
- Nginx &gt;= 1.9.

**NOTE:** Working with the earlier versions were not tested, but it is possible that everything is working.

### How to use

[](#how-to-use)

Include **Conf.php** file and import the class `Nemiro\Nginx\Conf`.

```
# include the class file (use own path of the file location)
require_once 'Nginx/Conf.php';

# import class
use Nemiro\Nginx\Conf as NginxConf;
```

#### Load config from file

[](#load-config-from-file)

```
# create instance and load config from file
$conf = new NginxConf('/etc/nginx/sites-available/example.org.conf');
# or
# $conf = NginxConf::CreateFromFile('/etc/nginx/sites-available/example.org.conf');

# get values
var_dump($conf['server']);

if ($conf['server']->ContainsChild('listen'))
{
  print_r($conf['server']['listen']->ParametersAsString());
}

var_dump($conf['server']['server_name']->ParametersAsString());
var_dump($conf['server']['root']->ParametersAsString());
var_dump($conf['server']['location']);
```

#### Load config from string

[](#load-config-from-string)

```
# config data
$str = 'server {
  # server name
  server_name            example.org;
  root                   /home/example.org/html; # root path
  auth_basic             "Test server";
  auth_basic_user_file   /home/example.org/.htpasswd;

  # location #1
  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For  $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080;
  }

  # location #2
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
  }

}';

# parse string
$conf = NginxConf::CreateFromString($str);

# get values
var_dump($conf['server']);
var_dump($conf['server']['server_name']->ParametersAsString());
var_dump($conf['server']['root']->ParametersAsString());

# get first location
$location = $conf['server']['location'][0];
var_dump($location);

# get second location
$location2 = $conf['server']['location'][1];
var_dump($location2);
```

#### Save to file

[](#save-to-file)

```
# load from file
$conf = NginxConf::CreateFromFile('/etc/nginx/sites-available/example.org.conf');

# set values
$conf['server']['server_name']->Parameters = array('example.org', 'www.example.org');
$conf['server']['root']->Parameters = array('/home/example.org/www');

# create a new directive
$new_location = NginxConf::CreateDirective('location');

# single name directives
$new_location->AddDirective('index', array('Default.aspx', 'default.aspx'));
$new_location->AddDirective('proxy_pass', array('http://127.0.0.1:8080'));

# directives with same name (group)
$proxy_set_header = NginxConf::CreateGroup('proxy_set_header');
$proxy_set_header->AddDirective(array('X-Real-IP', '$remote_addr'));
$proxy_set_header->AddDirective(array('X-Forwarded-For', '$remote_addr'));
$proxy_set_header->AddDirective(array('Host', '$host'));

# add the proxy_set_header to the new location
$proxy_set_header->AddTo($new_location);

# add the new location to the server directive
$new_location->AddTo($conf['server']);

# save
$conf->Save();

# or save as...
# $conf->Save('newFileName.conf');
```

#### Get string from current instance

[](#get-string-from-current-instance)

```
# load from file
$conf = new NginxConf::CreateFromFile('/etc/nginx/sites-available/example.org.conf');

# set values
$conf['server']['server_name']->Parameters = array('example.org', 'www.example.org');
$conf['server']['root']->Parameters = array('/home/example.org/www');

# create a new directive
$new_location = NginxConf::CreateDirective('location');

# single name directives
$new_location->AddDirective('index', array('Default.aspx', 'default.aspx'));
$new_location->AddDirective('proxy_pass', array('http://127.0.0.1:8080'));

# directives with same name (group)
$proxy_set_header = NginxConf::CreateGroup('proxy_set_header');
$proxy_set_header->AddDirective(array('X-Real-IP', '$remote_addr'));
$proxy_set_header->AddDirective(array('X-Forwarded-For', '$remote_addr'));
$proxy_set_header->AddDirective(array('Host', '$host'));

# add the proxy_set_header to the new location
$proxy_set_header->AddTo($new_location);

# add the new location to the server directive
$new_location->AddTo($conf['server']);

# get as string
$string = $conf->GetAsString();

# show string
var_dump($string);
```

#### Create a new config

[](#create-a-new-config)

```
# create an instance
$conf = new NginxConf();

# create and add server directive
$conf->Add(NginxConf::CreateDirective('server'));

# add directives to server directive
$conf['server']->AddDirective('server_name', array('example.org', 'www.example.org'));
$conf['server']->AddDirective('root', array('/home/example.org/www'));

# create a new location directive
$location = NginxConf::CreateDirective('location');

# add sub-directives
$location->AddDirective('index', array('index.php', 'index.html', 'index.htm'));

# add the location to the server directive
$location->AddTo($conf['server']);

# get as string
$string = $conf->GetAsString();

# show string
var_dump($string);

# or save
# $conf->Save('example.org.conf');
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

3782d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2475fd956b57400794960b56d5f8d44e106b5373e425c6ed2b2975d4756ce19?d=identicon)[aleksey.nemiro](/maintainers/aleksey.nemiro)

---

Top Contributors

[![alekseynemiro](https://avatars.githubusercontent.com/u/6204692?v=4)](https://github.com/alekseynemiro "alekseynemiro (5 commits)")

---

Tags

phpconfigparsernginxconf

### Embed Badge

![Health badge](/badges/alekseynemiro-nginxconfphp/health.svg)

```
[![Health](https://phpackages.com/badges/alekseynemiro-nginxconfphp/health.svg)](https://phpackages.com/packages/alekseynemiro-nginxconfphp)
```

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k942.7M149](/packages/doctrine-lexer)[romanpitak/nginx-config-processor

Nginx configuration files processor.

6935.7k1](/packages/romanpitak-nginx-config-processor)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1891.3M15](/packages/simplehtmldom-simplehtmldom)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23790.9k2](/packages/corveda-php-sandbox)[jakoch/nginx-conf

A Nginx Conf parser and generator.

111.5k](/packages/jakoch-nginx-conf)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

276.8k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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