宝塔面板安装云锁Nginx自编译web防护教程
宝塔安装请采用编译安装 Nginx!
本教程不适用于非宝塔用户以及 Apache 用户
配置编译环境
yum install -y gcc gcc-c++ pcre-devel openssl openssl-devel
查看 Nginx 位置
ps -elf | grep nginx
备份 宝塔 Nginx
cd /www/server/nginx/sbin/
cp nginx nginx.bak
下载云锁防护模块压缩包
wget //codeload.github.com/yunsuo-open/nginx-plugin/zip/master -O nginx-plugin-master.zip
unzip nginx-plugin-master.zip
cd nginx-plugin-master/
pwd
查看宝塔编译好的 Nginx 加载模块,在重新编译加载云锁防护模块的时候仍需加载这些模块
nginx -V
注意这个命令是大写的V,如果小写 v 是不会显示模块的
将 ./configure arguents:之后的内容复制到记事本备用,比如我的是:
--user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-http_concat_module --with-ld-opt=-Wl,-E --with-jemalloc --without-http_upstream_session_sticky_module --with-pcre=pcre-8.40
(我的仅供参考,实际以自己的为准)
编译内容
cd /www/server/nginx/src
./configure
上一步记事本中的备用内容 加上 --add-module=/root/nginx-plugin-master
./configure
和记事本复制的内容之间有个空格,后面的 --add-module
前面也有个空格,比如我的编译命令为:
./configure --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-http_concat_module --with-ld-opt=-Wl,-E --with-jemalloc --without-http_upstream_session_sticky_module --with-pcre=pcre-8.40 --add-module=/root/nginx-plugin-master
(我的仅供参考,实际以自己的为准)
./configure 上一步的内容 --add-module=/root/nginx-plugin-master
编译完成后将 ngx_modules.c
中的 &ngx_http_yunsuo_module
, 向下移动到 ngx_http_userid_filter_module
和 ngx_http_headers_filter_module
之间。(已在此之间的则可忽略)
Nginx1.8.0
以上和Tengine 2.2.0
则需要修改objs/Makefile
文件和objs/ngx_modules.c
来支持POST
过滤和内容过滤
首先,在 Makefile
文件中的 CFLAGS=...-Werror -g
后追加宏定义 -DHIGHERTHAN8
vi objs/Makefile
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -DHIGHERTHAN8
然后将 ngx_modules.c
中的 &ngx_http_yunsuo_module
,向下移动
vi objs/ngx_modules.c
ngx_module_t *ngx_modules[] = {
&ngx_core_module,
......
&ngx_http_upstream_keepalive_module,
&ngx_http_upstream_zone_module,
-----------下面这行向下移动----------------
`&ngx_http_yunsuo_module`,
------------------------------------------
&ngx_http_stub_status_module,
......
&ngx_http_userid_filter_module,
---------------移动到该位置-----------------
&ngx_http_yunsuo_module,
-------------------------------------------
&ngx_http_headers_filter_module,
&ngx_http_copy_filter_module,
&ngx_http_range_body_filter_module,
&ngx_http_not_modified_filter_module,
NULL
};
char *ngx_module_names[] = { "objs/ngx_modules.c" 186L, 6441C
......
};
修改后进行 make
(如原本无 Nginx
,make
后还需 make install
)
make
make
完成后将系统中原有的 Nginx
用重新编译生成的 Nginx
文件替换,替换后重启 Nginx
使新编译 Nginx
生效
复制新编译的 Nginx
rm -rf /www/server/nginx/sbin/nginx
cp /www/server/nginx/src/objs/nginx /www/server/nginx/sbin/
service nginx restart
重启 Nginx
service nginx restart
输入你的网址后面加上 /?order%20by
,测试云锁