PHP Classes

File: SmallServerAdmin/Libs/Nemiro/Nginx/README.ru.md

Recommend this page to a friend!
  Classes of Aleksey Nemiro   PHP Small Server Administrator   SmallServerAdmin/Libs/Nemiro/Nginx/README.ru.md   Download  
File: SmallServerAdmin/Libs/Nemiro/Nginx/README.ru.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Small Server Administrator
Web panel for small Debian and Ubuntu servers
Author: By
Last change:
Date: 7 years ago
Size: 8,177 bytes
 

Contents

Class file image Download

NginxConf.PHP Latest Stable Version Total Downloads License

NginxConf.PHP - ????????? ????? ??????? ??? ?????? ? ??????? ???????????? Nginx.

???????? ??? NginxConf.PHP ??????????????? ?? ???????? ???????? Apache License Version 2.0.

??????????

  • PHP5 >= 5.5, PHP7;
  • Nginx >= 1.9.

??????????: ?????? ? ??????? ???????? ?????? ?? ???????????, ?? ? ?????? ????????.

??? ????????????

?????????? ???? Conf.php ? ???????????? ????? `Nemiro\Nginx\Conf`.

# ?????????? ???? Conf.php (??????? ?????????? ???? ? ?????)
require_once 'Nginx/Conf.php';

# ??????? ??????? ?????? Conf - NginxConf
use Nemiro\Nginx\Conf as NginxConf;

???????? ????? ????????????

# ??????? ????????? ?????? Conf ? ????????? ???? ? ????? ????????????,
# ??????? ??????? ????????? ? ?????????
$conf = new NginxConf('/etc/nginx/sites-available/example.org.conf');
# ?????????????? ???????:
# $conf = NginxConf::CreateFromFile('/etc/nginx/sites-available/example.org.conf');

# ??? ???????, ??????? ?????????? ???????? server
var_dump($conf['server']);

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

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

# ??????? ???????? location
var_dump($conf['server']['location']);

???????? ???????????? ?? ??????

# ????????? ?????? ? ??????? ????????????
$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;
  }

}';

# ????????? ??????
$conf = NginxConf::CreateFromString($str);

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

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

# ??????? ?????? ??????? location
$location2 = $conf['server']['location'][1];
var_dump($location2);

?????????? ?????

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

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

# ??????? ????? ??????? location
$new_location = NginxConf::CreateDirective('location');

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

# ????????? ?????? ?????????
$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'));

# ????????? ????????? ?????? proxy_set_header ? ????????? ??????? location 
$proxy_set_header->AddTo($new_location);

# ???????? ????????? ??????? location ? ??????? server
$new_location->AddTo($conf['server']);
# ---------------------------------------------------------------------------------------

# ?????????? ????????? ? ???????? ????
$conf->Save();

# ??? ????? ??????? ??? ?????, ? ??????? ????? ????????? ??????
# $conf->Save('newFileName.conf');

????????? ???????????? ? ???? ?????? ?? ???????? ?????????? ??????

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

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

# ??????? ????? ??????? location
$new_location = NginxConf::CreateDirective('location');

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

# ????????? ?????? ?????????
$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'));

# ????????? ????????? ?????? proxy_set_header ? ????????? ??????? location 
$proxy_set_header->AddTo($new_location);

# ???????? ????????? ??????? location ? ??????? server
$new_location->AddTo($conf['server']);
# ---------------------------------------------------------------------------------------

# ???????? ???????????? ? ???? ??????
$string = $conf->GetAsString();

# ??????? ??????
var_dump($string);

???????? ???????????? ? ????

# ??????? ?????? ????????? ?????? Conf
$conf = new NginxConf();

# ??????? ???????? ??????? server
$conf->Add(NginxConf::CreateDirective('server'));

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

# ??????? ????? ??????? location
$location = NginxConf::CreateDirective('location');

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

# ???????? location ? server
$location->AddTo($conf['server']);

# ???????? ???????????? ? ???? ??????
$string = $conf->GetAsString();

# ??????? ??????
var_dump($string);

# ??? ????? ????????? ???????????? ? ????
# $conf->Save('example.org.conf');