[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用户:117.69.*.*
1 天前 Internet Explorer Windows 7
IP用户:20.171.*.*
1 天前 GPTBot
IP用户:183.166.*.*
2 天前 Internet Explorer Windows XP
IP用户:116.76.*.*
2 天前 UC Browser Android 7.1
IP用户:120.35.*.*
2 天前 Maxthon Windows 7
IP用户:43.153.*.*
3 天前 Mobile Safari iOS 13.2
IP用户:51.222.*.*
3 天前 aHrefs Bot
IP用户:110.87.*.*
4 天前 Internet Explorer Windows 8.1
IP用户:114.104.*.*
6 天前 Chrome Windows 7
IP用户:14.103.*.*
6 天前 Chrome Windows 10
IP用户:112.192.*.*
7 天前 Baidu Spark Windows 8
IP用户:223.215.*.*
9 天前 Chrome Windows 10
累计浏览次数:1476
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。
最近浏览 点击登录
累计浏览次数:221682
一周浏览次数:1853
今日浏览次数:58

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

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

鲁ICP备19027671号-2