云锁防火墙编译安装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 void
  ngx_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 void
  ngx_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扫一扫:

在这里插入图片描述

  • 15
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linlinlove2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值