当前位置: 首页 > news >正文

云锁防火墙编译安装nginx-plugin模块

一般情况下,当用户安装云锁的时候,云锁会自动适配nginx版本,使用我们已经预编译好的包含云锁模块的nginx备份并替换掉您当前系统中使用的nginx。卸载时,会将系统原始nginx文件替换回来。因此,云锁可保护使用nginx搭建的网站,开创了这个领域的先河。 我们秉承着让安全变得更简单的宗旨,使云锁尽可能多的适配广大用户的nginx版本(目前无法覆盖所有nginx版本),决定开放云锁nginx模块的源码,让有能力的小伙伴们自己动手同云锁一起打造一个安全的nginx环境。

一 、编译云锁nginx模块

步骤如下:

1.为避免意外情况发生, 请先将系统当前使用中的nginx进行备份(包括相关的网站配置文件)

2.wget https://codeload.github.com/yunsuo-open/nginx-plugin/zip/master -O nginx-plugin-master.zip

3.unzip nginx-plugin-master.zip

4.cd nginx-plugin-master

5.pwd 获取当前云锁插件源码所在目录的全路径 (假设为:/home/nginx-plugin-master,实际情况以pwd输出为准)

6.以下两种情况, 可以跳过这一步骤: 1)您的 nginx 是 tengine。 2)nginx 版本大于等于 1.8.0 并且 安装的云锁为V3, 此时需要关注 第 8 条说明。

除以上两种情况,对于 nginx 来说,由于其不支持post过滤,所以需要修改nginx源码目录下src/http/ngx_http_upstream.c 文件,步骤如下:

a.查找 static void ngx_http_upstream_init_request(ngx_http_request_t *r)函数,在其所在行上方添加:int ngx_http_yunsuo_post_in_handler(ngx_http_request_t *r);

b.在ngx_http_upstream_init_request函数开头,变量声明后,添加:

if(ngx_http_yunsuo_post_in_handler(r)) {return;}

以nginx-1.0.11为例:
修改前源码:

  static voidngx_http_upstream_init_request(ngx_http_request_t *r){ngx_str_t                      *host;ngx_uint_t                      i;ngx_resolver_ctx_t             *ctx, temp;ngx_http_cleanup_t             *cln;ngx_http_upstream_t            *u;ngx_http_core_loc_conf_t       *clcf;ngx_http_upstream_srv_conf_t   *uscf, **uscfp;ngx_http_upstream_main_conf_t  *umcf;if (r->aio) {return;}u = r->upstream;......}

修改后源码:

  /*这段是添加的*/int ngx_http_yunsuo_post_in_handler(ngx_http_request_t *r);/*------------*/static voidngx_http_upstream_init_request(ngx_http_request_t *r){ngx_str_t                      *host;ngx_uint_t                      i;ngx_resolver_ctx_t             *ctx, temp;ngx_http_cleanup_t             *cln;ngx_http_upstream_t            *u;ngx_http_core_loc_conf_t       *clcf;ngx_http_upstream_srv_conf_t   *uscf, **uscfp;ngx_http_upstream_main_conf_t  *umcf;/*这段是添加的*/if(ngx_http_yunsuo_post_in_handler(r)) {return;}/*------------*/if (r->aio) {return;}u = r->upstream;......}

7.云锁的nginx插件模块是标准的nginx模块,所以您在编译nginx过程中,configure时只要添加额外参数–add-module=/home/nginx-plugin-master(注意:/home/nginx-plugin-master为示例,实际路径以步骤5中pwd命令为准)即可让nginx支持云锁的功能,示例如下:

假设您之前configure时的命令如下:

  ./configure --prefix=/usr/local/nginx --with-http_stub_status_module \--with-http_ssl_module --with-http_gzip_static_module \--add-module=../ngx_cache_purge-1.3 

现在的configure时的命令如下:

  ./configure --prefix=/usr/local/nginx --with-http_stub_status_module \--with-http_ssl_module --with-http_gzip_static_module \--add-module=../ngx_cache_purge-1.3  --add-module=/home/nginx-plugin-master

8、以下两种情况, 跳过此步骤:
1)您的 nginx 是 tengine。
2)在步骤 6 中 已经做过了配置。 当您的 nginx 版本大于等于 1.8.0 并且安装的云锁为V3时,想要支持 POST 防护, 只需在 configure 生成的 Makefile (即 objs/Makefile 文件)中 CFLAGS 追加宏定义 HIGHERTHAN8 形如 : CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
修改为:CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DHIGHERTHAN8

9、编译 nginx (注意:如果原本已经有 nginx, 只执行 make 即可,make install 会覆盖掉你的 nginx.conf)

10、将系统当前使用中的nginx二进制文件替换为刚刚编译好的包含了云锁模块的nginx文件即可

二 、让云锁识别您自己编译的nginx(V3版本云锁不需要执行此步骤)

1、安装云锁,如果您已经安装了云锁,可跳过此步骤。如果还没有,请到http://www.yunsuo.com.cn/ht/software/下载并安装云锁
2、cd /usr/local/yunsuo_agent/nginx/
3、./configure_compile_nginx nginx_install_path (nginx_install_path为nginx的安装路径,即configure时 --prefix=path如果未指定过路径, 那么默认为/usr/local/nginx)

技术交流 QQ扫一扫:

在这里插入图片描述

http://www.lryc.cn/news/283956.html

相关文章:

  • 【服务器数据恢复】服务器迁移数据时lun数据丢失的数据恢复案例
  • 6.4.2转换文件
  • 智能驾驶新浪潮:SSD与UFS存储技术如何破浪前行?-UFS篇
  • TS 学习笔录(持续更新中)
  • RabbitMQ安装和使用
  • 使用pyechart创建折线图
  • Vue3+Ts:使用i18n实现国际化与全局动态下拉框框切换语言
  • 多目标优化中常用的差分进化算法DE【2】
  • 游卡:OceanBase在游戏核心业务的规模化降本实践
  • LightDB - oracle_fdw 过滤条件下推增强【24.1】
  • 【计算机网络】HTTP协议以及简单的HTTP服务器实现
  • 04 SpringBoot整合Druid/MyBatis/事务/AOP+打包项目
  • C++程序编译时的_GLIBCXX_USE_CXX11_ABI参数的值选择,适配昇腾Transformer推理加速库与LLM推理模型库
  • 什么是站群服务器?
  • 《WebKit 技术内幕》之四(3): 资源加载和网络栈
  • vue3-模板引用
  • 聚类模型评估指标
  • 测试 ASP.NET Core 中间件
  • 智能小程序小部件(Widget)媒体组件属性说明和示例代码汇总
  • enum的比较
  • 网工每日一练(1月15日)
  • henauOJ 1113: 计算x的n次方
  • 64.Spring事件监听的核心机制是什么?
  • 《C++大学教程》3.12Account类
  • 【工作记录】基于springboot3+springsecurity实现多种方式登录及鉴权(二)
  • CSS笔记III
  • Bit.Store 加密卡集成主流 BRC20通证,助力 BTC 生态流动性
  • openssl3.2 - 官方demo学习 - mac - siphash.c
  • (六)深入理解Bluez协议栈之“GATT Client Profile”
  • SVO编译