nginx实现网站过滤
替换掉网站页面上的敏感词汇。
实验环境:
操作系统:CentOS 7
服务器:192.168.184.137
nginx版本:nginx-1.16.1
nginx的网站过滤步骤如下:
1、关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld # 关闭防火墙
[root@localhost ~]# systemctl disable firewalld # 开机自动关闭防火墙
[root@localhost ~]# setenforce 0 # 临时关闭selinux
[root@localhost ~]# vim /etc/selinux/config # 永久关闭selinux,要重启机器才生效(reboot)
SELINUX=disabled # 将enforcing修改为disabled
2、配置基础的nginx环境
[root@localhost ~]# yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
[root@localhost ~]# yum -y install net-tools wget lsof
[root@localhost ~]# wget http://nginx/download/nginx-1.16.1.tar.gz
[root@localhost ~]# tar xf nginx-1.16.1.tar.gz
[root@localhost ~]# cd nginx-1.16.1
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_sub_module
[root@localhost nginx-1.16.1]# make && make install
[root@localhost nginx-1.16.1]# cd
3、修改配置文件(/usr/local/nginx/conf/nginx.conf)
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
43 location / {
44 root /web/html; #创建新的路径(大概在文件的44行)
45 index index.html index.htm;
46 sub_filter nginx 'apache'; #表示过滤nginx,替换成apache(大概在文件的46行)
47 sub_filter_once off; #on表示只匹配一次,off表示所有都匹配(大概在文件的47行)
48 }
4、在/web/html/创建测试文件
[root@localhost ~]# mkdir -p /web/html
[root@localhost ~]# cd /web/html/
[root@localhost html]# vim index.html
<p>i am 192.168.184.137's testing page</p>
<p>nginx tomcat</p>
<p>i am nginx</p>
<p>welcome to nginx</p>
<p>you can write</p>
[root@localhost html]# cd
5、二进制启动nginx,重新加载(reload)
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
6、浏览器测试 — 192.168.184.137
发现页面上的nginx,都被替换成了apache。
更多推荐
nginx实现网站过滤
发布评论