VeryNginx —— Nginx 強化版本

akan 8年前發布 | 20K 次閱讀 Nginx Git Web服務器

來自: http://git.oschina.net/0ldm0s/VeryNginx

VeryNginx

VeryNginx is a very powerful and friendly nginx .

版權說明

這個軟件的原作者并不是我。我只是去除了openrestry包的依賴,并且可以直接自動化安裝而已。

目前測試通過的版本是ubuntu 14.04 TLS,其他版本暫時未測試。

原作者網站

介紹

VeryNginx 基于 lua_nginx_module(openrestry) 開發,實現了高級的防火墻、訪問統計和其他的一些功能。 強化了 Nginx 本身的功能,并提供了友好的 Web 交互界面。

Nginx 運行狀態分析

  • 每秒請求數
  • 響應時間
  • 網絡流量
  • 網絡連接數

請求過濾

VeryNginx 可以基于按照以下信息對請求進行過濾:

  • IP
  • UserAgent
  • 請求路徑 (URI)
  • 請求參數

VeryNginx 預置了常用的過濾規則,可以在一定程度上阻止常見的 SQL 注入、Git 及 SVN 文件泄露、目錄遍歷攻擊,并攔截常見的掃描工具。

同時 VeryNginx 的過濾器還支持 IP 黑/白名單設置

訪問統計

VeryNginx 可以統計網站每個URI的訪問情況,包括每個URI的:

  • 總請求次數
  • 各狀態碼次數
  • 返回總字節數
  • 每請求平均字節數
  • 總響應時間
  • 平均響應時間

并且可以按各種規則排序進行分析。

安裝說明

安裝 Nginx / OpenResty

VeryNginx 基于 OpenResty[

openresty],所以你需要先安裝它:

wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz
tar -xvzf ngx_openresty-1.9.7.1.tar.gz
cd ngx_openresty-1.9.7.1
sudo su
./configure --prefix=/opt/VeryNginx --user=nginx --group=nginx --with-http_stub_status_module --with-luajit
gmake
gmake install

VeryNginx 實際使用到了 OpenResty 中的這些模塊

如果你不想安裝 OpenResty,或者你已經有了一個正在工作的 Nginx,你也可以自己手動為 Nginx 編譯安裝這些模塊

部署 VeryNginx

克隆 VeryNginx 倉庫到本地, 復制 nginx.conf 和 VeryNginx 文件夾到 Nginx 的工作目錄.

cd ~
git clone https://github.com/alexazhou/VeryNginx.git
rm -f /opt/VeryNginx/nginx/conf/nginx.conf
cp ~/VeryNginx/nginx.conf /opt/VeryNginx/nginx/conf/nginx.conf
cp -r ~/VeryNginx/VeryNginx /opt/VeryNginx/VeryNginx

下面是使 /opt/VeryNginx 對 nginx 是可寫的, 這樣 VeryNginx 可以把自己的配置保存在里面

修改/opt/VeryNginx目錄的所有者為nginx用戶

chown -R nginx:nginx /opt/VeryNginx</pre>

編輯 Nginx 配置文件

VeryNginx 項目提供了一個配置模版 /opt/VeryNginx/nginx/nginx.conf 。你需要把自己站點的 Nginx 配置加到這個模版里面。 但是記得不要修改配置 VeryNginx 的那部分代碼(除非你知道自己在干啥 :smiling_imp:)。

配置 VeryNginx 的代碼是下面這部分:

#-----------------VeryNginx config code------------------
lua_package_path '/opt/VeryNginx/VeryNginx/lua_script/?.lua;;/opt/VeryNginx/VeryNginx/lua_script/module/?.lua;;';
lua_package_cpath '/opt/VeryNginx/VeryNginx/lua_script/?.so;;';
lua_code_cache on;

lua_shared_dict status 1m; lua_shared_dict summary_long 10m; lua_shared_dict summary_short 10m;

init_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_init.lua; rewrite_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_rewrite.lua; access_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_access.lua; log_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_log.lua;

---------------VeryNginx config code end-----------------</pre>

如果不使用 VeryNginx 提供的配置模版,你也可以手動把這部分加入到自己的 Nginx 配置文件中. (如果安裝路徑不是 /opt/VeryNginx ,需要對 lua_package_cpath 和 lua_package_path 的值進行修改)

啟動服務

/opt/VeryNginx/nginx/sbin/nginx

停止服務

/opt/VeryNginx/nginx/sbin/nginx -s stop

對 VeryNginx 進行配置

打開瀏覽器訪問 http://127.0.0.1/VeryNginx/dashboard/index.html 。

默認用戶名和密碼是 verynginx / verynginx 。

登錄之后就可以查看狀態,并對配置進行修改了。修改配置后,記得到 「配置 > 系統 > 全部配置」去保存.

提示

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

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

  • 如果因為配錯了什么選項,導致無法登錄,可以手動刪除 config.json 來清空配置。

Enjoy~

Installation

Install Nginx / OpenResty

VeryNginx is based on OpenResty, so you need to install it first.

wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz
tar -xvzf ngx_openresty-1.9.7.1.tar.gz
cd ngx_openresty-1.9.7.1
sudo su
./configure --prefix=/opt/VeryNginx --user=nginx --group=nginx --with-http_stub_status_module --with-luajit
gmake
gmake install

VeryNginx uses only following modules in OpenResty.

If you don't want to install OpenResty, or you already have a working installation of Nginx, you can always configure your Nginx with those modules manually.

The nginx-extras package from your Linux distro is usually a good start.

Deploy VeryNginx

Checkout VeryNginx repository, link nginx.conf and VeryNginx folder to nginx config directory.

cd ~
git clone https://github.com/alexazhou/VeryNginx.git
rm -f /opt/VeryNginx/nginx/conf/nginx.conf
cp ~/VeryNginx/nginx.conf /opt/VeryNginx/nginx/conf/nginx.conf
cp -r ~/VeryNginx/VeryNginx /opt/VeryNginx/VeryNginx

The following line makes /opt/VeryNginx writable for nginx, so that VeryNginx can modify configs inside it.

Change user and group name to the actual account.

chown -R nginx:nginx /opt/VeryNginx</pre>

Configure Nginx

You should add your sites into /opt/VeryNginx/nginx/nginx.conf . However you should not modify the VeryNginx config code in the file unless you know what you're doing :smiling_imp:.

VeryNginx config code looks like the following:

#-----------------VeryNginx config code------------------
lua_package_path '/opt/VeryNginx/VeryNginx/lua_script/?.lua;;/opt/VeryNginx/VeryNginx/lua_script/module/?.lua;;';
lua_package_cpath '/opt/VeryNginx/VeryNginx/lua_script/?.so;;';
lua_code_cache on;

lua_shared_dict status 1m; lua_shared_dict summary_long 10m; lua_shared_dict summary_short 10m;

init_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_init.lua; rewrite_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_rewrite.lua; access_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_access.lua; log_by_lua_file /opt/VeryNginx/VeryNginx/lua_script/on_log.lua;

---------------VeryNginx config code end-----------------</pre>

You can have your own Nginx installation to work with VeryNginx by integrating its config code into you own config file.

Start service

/opt/VeryNginx/nginx/sbin/nginx

Stop service

/opt/VeryNginx/nginx/sbin/nginx -s stop

Configure VeryNginx

Open your web browser and go to http://127.0.0.1/VeryNginx/dashboard/index.html .

Default user and password is verynginx / verynginx . You should be able to work through all the options now.

Don't forget to visit "配置 > 系統 > 全部配置" to save your changes.

Tips

  • New configs will be effective immediately upon saving. It's not necessary to restart or reload nginx.

  • When you save config, VeryNginx will write all configs to /opt/VeryNginx/VeryNginx/config.json .

  • If you lock yourself out of VeryNginx by doing something stupid, you can always delete config.json to revert VeryNginx to its default.

Enjoy~

[ openresty]: OpenResty 是一個Nginx再發行版本,包含了標準Nginx以及很多擴展模塊.

</div>

 本文由用戶 akan 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!