[romanpitak/nginx-config-processor]一个Nginx配置文件生成器

2022-03-21 奥古斯宏
使用对象的方法用法为Nginx生成配置文件

这是一个生成和处理Nginx配置文件的扩展库,可以使用简单地类方法生成Nginx的配置文件.

安装扩展非常简单:

composer require romanpitak/nginx-config-processor

比如这样:

<?php
require_once __DIR__.'/vendor/autoload.php';

use RomanPitak\Nginx\Config\Directive;
use RomanPitak\Nginx\Config\Scope;

Scope::create()
    ->addDirective(Directive::create('server')
        ->setChildScope(Scope::create()
            ->addDirective(Directive::create('listen', 8080))
            ->addDirective(Directive::create('server_name', 'example.net'))
            ->addDirective(Directive::create('root', 'C:/www/example_net'))
            ->addDirective(Directive::create('location', '^~ /var/', Scope::create()
                    ->addDirective(Directive::create('deny', 'all'))
                )->setCommentText('Deny access for location /var/')
            )
        )
    )
    ->saveToFile('example.net');

最终生成的配置文件如下:

server {
    listen 8080;
    server_name example.net;
    root C:/www/example_net;
    location ^~ /var/ { # Deny access for location /var/
        deny all;
    }
}

同时还支持其他的方法,比如设置注释等,同时也支持解析现有的配置文件,简单好用.

最近浏览
IP用户:14.1.*.*
2 天前 Yandex Browser Windows 10
IP用户:43.167.*.*
2 天前 Mobile Safari iOS 13.2
IP用户:40.77.*.*
9 天前 BingBot
IP用户:20.171.*.*
11 天前 GPTBot
IP用户:112.43.*.*
11 天前 Microsoft Edge Windows 10
IP用户:154.207.*.*
13 天前 Chrome Windows 10
IP用户:223.109.*.*
13 天前 Sogou Spider
IP用户:43.157.*.*
13 天前 Mobile Safari iOS 13.2
IP用户:85.208.*.*
13 天前 Semrush Bot
IP用户:144.76.*.*
15 天前 BLEXBot Crawler
IP用户:52.71.*.*
17 天前 Amazon Bot
IP用户:216.73.*.*
20 天前 Generic Bot
累计浏览次数:1569
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。

本站所有权利归 phpreturn.com 所有

举报/反馈/投稿邮箱:phpreturn@ulthon.com

鲁ICP备19027671号-2