mirror of
https://github.com/envoyr/nginx-configurator.git
synced 2026-04-28 04:06:18 +00:00
remove parser and add collection package into this library
This commit is contained in:
@@ -9,34 +9,22 @@ use Envoyr\NginxConfigurator\Node\Param;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$uuid = 'uuid';
|
||||
|
||||
$factory = new Factory();
|
||||
$builder = new Builder();
|
||||
$builder->append(new Directive('proxy_cache_path', [new Param("/data/nginx/cache/{$uuid}"), new Param("keys_zone={$uuid}:10m")]));
|
||||
|
||||
$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 Directive('error_log', [new Param("/data/nginx/log/{$uuid}.log"), new Param('debug')]));
|
||||
$server->append(new Directive('proxy_cache', [new Param($uuid)]));
|
||||
$server->append(new Location(new Param('/'), null, [
|
||||
new Directive('error_page', [new Param('401')]),
|
||||
new Directive('host', [new Param('example.com')]),
|
||||
new Directive('proxy_pass', [new Param('https://example.com')]),
|
||||
]));
|
||||
$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')]),
|
||||
$server->append(new Location(new Param('/.well-known/acme-challenge'), new Param('^~'), [
|
||||
new Directive('proxy_pass', [new Param('https://le.cdn.gd')])
|
||||
]));
|
||||
|
||||
print($builder->dump());
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Envoyr\NginxConfigurator\Builder;
|
||||
use Envoyr\NginxConfigurator\Config\Server;
|
||||
use Envoyr\NginxConfigurator\Node\Node;
|
||||
use Envoyr\NginxConfigurator\Parser;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$config = <<<CONFIG
|
||||
server {
|
||||
listen 8080;
|
||||
root /data/www/web;
|
||||
index index.php index.html index.htm;
|
||||
|
||||
location / {
|
||||
try_files \$uri \$uri/ /index.php;
|
||||
}
|
||||
|
||||
error_page 404 /404.html;
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/www;
|
||||
}
|
||||
|
||||
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
|
||||
location ~ \.php$ {
|
||||
try_files \$uri =404;
|
||||
fastcgi_pass unix:/var/run/php5-fpm.sock;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
CONFIG;
|
||||
|
||||
$parser = new Parser();
|
||||
$defaultConfig = $parser->parse($config);
|
||||
|
||||
/** @var Server $defaultServers[] */
|
||||
$defaultServers = $defaultConfig->search(function (Node $node) {
|
||||
return $node instanceof Server;
|
||||
});
|
||||
|
||||
|
||||
|
||||
$builder = new Builder();
|
||||
if (count($defaultServers) > 0) {
|
||||
/** @var Server $defaultServer */
|
||||
foreach ($defaultServers as $defaultServer) {
|
||||
$builder->append($defaultServer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user