1 Star 0 Fork 95

于斌 / VeryNginx

forked from AlexaZhou / VeryNginx 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

VeryNginx

VeryNginx 是一个功能强大而对人类友好的 Nginx 扩展程序.

###提示 v0.2 版本之后,控制台入口被移动到了 /verynginx/index.html

##介绍

VeryNginx 基于 lua_nginx_module(openrestry) 开发,实现了高级的防火墙、访问统计和其他的一些功能。 集成在 Nginx 中运行,扩展了 Nginx 本身的功能,并提供了友好的 Web 交互界面。

VeryNginx在线实例

用户名 / 密码: verynginx / verynginx

详细配置说明见:VeryNginx Github WiKi

###Nginx 运行状态分析

  • 每秒请求数
  • 响应时间
  • 网络流量
  • 网络连接数

Nginx 运行状态

###自定义行为

VeryNginx 包含强大的自定义功能,可以做很多事情

自定义行为包含两部分, Matcher 和 Action 。 Matcher 用来对请求进行匹配, Action 为要执行的动作

这样的优势在于把所有的前置判断整合在Matcher里一起来实现了,使复杂(组合)规则的实现变成了可能

####Matcher

一个 Matcher 用来判断一个 Http 请求是否符合指定的条件, 一个 Matcher 可以包含一个或者多个约束条件,目前支持以下几种约束:

  • Client IP
  • Host
  • UserAgent
  • URI
  • Referer
  • Request Args

当一个请求没有违反 Matcher 中包含的全部条件时,即命中了这个 Matcher

####Action

每个 Action 会引用一个 Matcher ,当 Matcher 命中时, Action 会被执行

目前已经实现了以下 Action

  • Scheme Lock 将访问协议锁定为 Https 或者 Http
  • Redirect 对请求进行重定向
  • URI Rewrite 对请求的 URI 进行内部重写
  • Browser Verify 通过set-cookies 和 js 验证客户端是否为浏览器,并拦截非浏览器流量。本功能可能会阻拦搜索引擎爬虫,建议仅在被攻击时开启,或者针对搜索引擎编写特别的规则。
  • Frequency Limit 访问频率限制
  • Filter(waf) 过滤器

因为 Matcher 可以对请求进行细致的匹配,所以结合 Filter Action,就可以实现一个高级的WAF,可以利用Matcher中所有的条件来对请求进行过滤,并返回指定状态码

VeryNginx 预置了常用的过滤规则,可以在一定程度上阻止常见的 SQL 注入、Git 及 SVN 文件泄露、目录遍历攻击,并拦截常见的扫描工具。

VeryNginx Matcher

VeryNginx filter

####Backend

每个 Backend 会引用一个 Matcher ,当 Matcher 命中时, 请求会通过 Backend 进行处理

目前已经实现了以下 Backend

  • Proxy Pass 将请求反向代理到其它服务器
  • Static File 使用本地文件处理请求

###访问统计

VeryNginx 可以统计网站每个URI的访问情况,包括每个URI的:

  • 总请求次数
  • 各状态码次数
  • 返回总字节数
  • 每请求平均字节数
  • 总响应时间
  • 平均响应时间

并且可以按各种规则排序进行分析。

Nginx 运行状态

##安装和使用说明

VeryNginx 基于 OpenResty[^openresty],所以安装 VeryNginx 需要先安装好 OpenResty。不过并不用担心安装过程中可能的麻烦,VeryNginx 自身提供了脚本来进行安装工作。

安装 VeryNginx

克隆 VeryNginx 仓库到本地, 然后进入仓库目录,执行以下命令

python install.py install

即可一键安装 VeryNginx 和 以及依赖的 OpenResty

想使用自己的 Nginx?

VeryNginx 可以自动为你安装依赖的 OpenResty,通常情况下你没有必要再自己安装 OpenResty。

但如果你想要使用自己编译的 Nginx( OpenResty ),也是可以的。具体方法请阅读Wiki中的这篇说明:Use own nginx

使用

编辑 Nginx 配置文件

VeryNginx 的配置文件位置为 /opt/verynginx/openresty/nginx/conf/nginx.conf,这是一个简单的示例文件,可以让你访问到 VeryNginx的控制面板。如果你想真正的用 VeryNginx 来做点什么,那你需要编辑这个文件,并将自己的 Nginx 配置加入到其中。

这个配置文件在普通的 Nginx 配置文件基础上添加了三条 Include 指令来实现功能,分别为

  • include /opt/verynginx/verynginx/nginx_conf/in_external.conf;
  • include /opt/verynginx/verynginx/nginx_conf/in_http_block.conf;
  • include /opt/verynginx/verynginx/nginx_conf/in_server_block.conf;

以上三条指令分别放在 http 配置块外部,http 配置块内部,server 配置块内部,在修改时请保留这三条。如果添加了新的 Server 配置块或 http 配置块,也需要在新的块内部加入对应的 include 行。

启动/停止/重启 服务

完成安装工作以后,可以通过以下命令来运行 VeryNginx

#启动服务
/opt/verynginx/openresty/nginx/sbin/nginx

#停止服务
/opt/verynginx/openresty/nginx/sbin/nginx -s stop

#重启服务
/opt/verynginx/openresty/nginx/sbin/nginx -s reload

###通过web面板对 VeryNginx 进行配置

VeryNginx 启动后,可以通过浏览器访问管理面板来查看状态以及进行配置。

管理面板地址为 http://{{your_machine_address}}/verynginx/index.html

默认用户名和密码是 verynginx / verynginx

登录之后就可以查看状态,并对配置进行修改了。修改配置后,点击保存才会生效.

故障排除

如果你在 安装 / 配置 / 使用 的过程中遇到任何问题, 你可以参考故障排除文档来解决.

故障排除

详细的配置说明

VeryNginx 按照易于使用的思想进行设计,如果你有一定的基础,或是对 Nginx 较了解,那么你应该可以直接在界面上使用。

当然 VeryNginx 也提供了详细的文档供你查阅。 VeryNginx Wiki

提示

  • 通过 VeryNginx 控制面板保存新配置之后,会立刻生效,并不需要 restart/reload Nginx。

  • VeryNginx 把配置保存在 /opt/verynginx/verynginx/configs/config.json 里面。

  • 状态页面图表默认带有动画效果,如果有卡顿,可以点右上角齿轮图标关掉动画效果

  • 如果因为配错了什么选项,导致无法登录,可以手动删除 config.json 来清空配置,或者手动编辑这个文件来修复。

更新 VeryNginx / OpenResty

随着时间的发展,VeryNginx 本身的代码会演进,也可以会支持更新版本的 OpenResty ,更新的代码可能会支持一些新的功能,或是修复了一些旧的bug。如果要更新本地已经安装的 VeryNginx ,你只需要先 pull github 上最新的代码到本地,然后通过以下命令来进行更新:

#更新 Verynginx
python install.py update verynginx

#更新 OpenResty
python install.py update openresty

install.py脚本在升级过程中,将保留原有的 config.json 和 nginx.conf, 所以更新的过程并不会丢失配置

构建VeryNginx docker 镜像

在将代码clone到本地之后,你可以运行下面的命令:

cd Docker
docker build -t verynginx .
docker run verynginx

然后用浏览器打开 http://{{your_docker_machine_address}}/verynginx/index.html

当然你也可以运行 docker run -p xxxx:80 verynginx 来映射一下你的container的端口到你的宿主机,默认是80,你可以把xxxx改成你希望的在宿主机上的端口号

捐赠

如果你喜欢 VeryNginx,那么你可以通过捐赠来支持我开发 VeryNginx。有了你的支持,我将可以让 VeryNginx 变的更好😎

PayPal

通过 PayPal 来支持 VeryNginx

微信

扫描下方的二维码来支持 VeryNginx

致谢

感谢大家对VeryNginx的帮助

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

VeryNginx 基于 Lua_Nginx_Module(openrestry) 开发,实现了高级的防火墙、访问统计和其他的一些功能。 强化了 Nginx 本身的功能,并提供了友好的 Web 交互界面。 展开 收起
Lua
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Lua
1
https://gitee.com/yubin99521/VeryNginx.git
git@gitee.com:yubin99521/VeryNginx.git
yubin99521
VeryNginx
VeryNginx
master

搜索帮助