[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用户:60.19.*.*
12 小时前 Microsoft Edge Windows 10
IP用户:221.10.*.*
19 小时前 Internet Explorer Windows 7
IP用户:185.191.*.*
21 小时前 Semrush Bot
IP用户:66.249.*.*
1 天前 Googlebot
IP用户:54.36.*.*
1 天前 aHrefs Bot
IP用户:123.189.*.*
1 天前 Firefox Windows 7
IP用户:54.36.*.*
2 天前 aHrefs Bot
IP用户:54.36.*.*
2 天前 aHrefs Bot
IP用户:80.244.*.*
2 天前 Safari Mac 12.5
IP用户:117.57.*.*
2 天前 Internet Explorer Windows 7
IP用户:117.69.*.*
3 天前 Baidu Spark Windows 8
IP用户:49.81.*.*
3 天前 Maxthon Windows XP
累计浏览次数:1069
评论
点击登录
phpreturn,PHP武器库,专注PHP领域的项目和资讯,收录和介绍PHP相关项目。
最近浏览 点击登录
累计浏览次数:154456
一周浏览次数:3315
今日浏览次数:450

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

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

鲁ICP备19027671号-2