[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用户:115.198.*.*
4 小时前 Firefox Windows 8.1
IP用户:121.229.*.*
4 小时前 Sogou Spider
IP用户:223.109.*.*
4 天前 Sogou Spider
IP用户:54.90.*.*
5 天前 Amazon Bot
IP用户:185.191.*.*
5 天前 Semrush Bot
IP用户:107.173.*.*
5 天前 Chrome Windows 10
IP用户:14.153.*.*
5 天前 Chrome Mobile Android 7.1
IP用户:116.179.*.*
9 天前 Baidu Spider
IP用户:20.171.*.*
9 天前 GPTBot
IP用户:66.249.*.*
14 天前 Googlebot
IP用户:74.80.*.*
14 天前 Generic Bot
IP用户:20.171.*.*
17 天前 GPTBot
累计浏览次数:1393
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。
最近浏览 点击登录
累计浏览次数:209111
一周浏览次数:2033
今日浏览次数:171

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

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

鲁ICP备19027671号-2