返回列表 发帖

CentOS6_Nginx反向代理+Nginx版网站安全狗+Tomcat+JDK+SSL

笺注:这是在 CentOS6_Tomcat+JDK+MySQL 的基础上做的


Nginx反向代理:
Nginx使用TCP 80端口,Tomcat使用TCP 8080端口;客户端先访问Nginx,通过Nginx的反向代理,再访问到Tomcat。


Nginx和Nginx版网站安全狗的安装可参考:Oracle Linux6安装服务器安全狗、Nginx版网站安全狗
备注:Linux系统下,网站安全狗有Nginx版,但没有Tomcat版。



确认Tomcat正在运行:
[root@localhost ~]# elinks 127.0.0.1:8080
图片1.png
2021-4-26 14:45



确认Nginx正在运行:
[root@localhost ~]# elinks 127.0.0.1
图片2.png
2021-4-26 14:45



查看Nginx的版本:
[root@localhost ~]# nginx -v
safedog-nginx-waf version/2.4
developed by www.safedog.cn

nginx version: nginx/1.10.2



Nginx的默认站点使用反向代理:

修改Nginx的主配置文件:
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
插入以下代码:
  proxy_pass      http://127.0.0.1:8080;

如下图:
图片3.png
2021-4-26 14:46

注释:把对本机TCP 80端口的访问反向代理到本机的TCP 8080端口。


重启Nginx服务:
[root@localhost ~]# service nginx restart



防火墙需要开启TCP 80端口、不需要开启TCP 8080端口:
[root@localhost ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Thu Jul  5 04:46:40 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6:680]
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Thu Jul  5 04:46:40 2018


重启iptables服务:
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则:[确定]
iptables:正在卸载模块:[确定]
iptables:应用防火墙规则:[确定]



查看防火墙的filter表的规则:
iptables -nL
图片4.png
2021-4-26 14:47




反向代理成功:(远程客户端只访问服务器的TCP 80端口)
http://192.168.168.135/
图片5.png
2021-4-26 14:47



http://192.168.168.135/mm.jsp
图片6.png
2021-4-26 14:47






############
############

测试Nginx版网站安全狗的漏洞防护功能:(要设置为 记录并拦截 )

相关的配置文件:
[root@localhost ~]# cd /etc/safedog/nginx/conf/
[root@localhost conf]# cat WPCDefSql.conf
[SqlAttack]
ChkFullUrl=1
ChkSqlAttackStatus=1
ChkUrlLenStatus=1
Count=0
MaxUrlLen=2048
NeedSendInterceptPage=1  #记录并拦截;默认是0,记录不拦截
NeedSendInterceptPageSQLAttack=0
SendAlert=1
UpdateUrl=http://www.safedog.cn/upload/configFile/sqlRule.dat
WhitePathCount=0

注释:可以直接在配置文件中修改,自动生效的。


客户端远程测试:
http://192.168.168.135/?order%20by
图片7.png
2021-4-26 14:48


结论:
Nginx做了反向代理后,Nginx版网站安全狗可以保护本机。













############
############

检测Nginx是否支持SSL:

[root@localhost ~]# nginx -V
safedog-nginx-waf version/2.4
developed by www.safedog.cn
nginx version: nginx/1.10.2
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46)
built with OpenSSL 1.0.2k  26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-ipv6 --with-http_auth_request_module --with-http_v2_module --with-pcre=../3th_lib/pcre-8.40 --with-openssl=../3th_lib/openssl-1.0.2k --with-cc-opt=-I../../../../Plugin_tag_before_yunyu/NginxSiteShield --with-ld-opt='-Wl,-rpath=/etc/safedog/libs/nginx -Wl,-rpath=/etc/safedog/libs/sdcommon -Wl,-rpath=/etc/safedog/libs/sdcc -Wl,-dynamic-linker=/etc/safedog/libs/sdcommon/ld-linux.so.2 -lstdc++ -lnginx_safedog_plugin -lWPCPlugin -lcurl -liconv -lSPModule -llog4cplus' _fuyun    --add-module=../module/3rd_part_module/ngx_cache_purge-2.3 --add-module=../module/3rd_part_module/nginx_upstream_check_module-master --add-module=../module/3rd_part_module/ngx_http_accounting_module-master --add-module=../module/3rd_part_module/testcookie-nginx-module-master

注释:有“--with-http_ssl_module”就可以了。



Nginx的默认站点使用SSL:

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
加入以下代码:( 记得把listen 80修改为 listen 443
ssl on;
ssl_certificate zhuohua.crt;
ssl_certificate_key zhuohua.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

如下图:
图片8.png
2021-4-26 14:50



SSL证书的创建可参考:Nginx基于域名的虚拟主机/域名重定向/访问控制/防盗链/SSL

上传SSL证书到服务器:
图片9.png
2021-4-26 14:51



重启Nginx服务:
[root@localhost ~]# service nginx restart



插入防火墙规则:(打开TCP 443端口)
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
iptables-save > /etc/sysconfig/iptables

现在防火墙不需要打开TCP 80端口了:
sed -i '/80/d' /etc/sysconfig/iptables
service iptables restart


再次查看防火墙的filter表的规则:
iptables -t filter -nL
图片10.png
2021-4-26 14:51




客户端远程测试:
https://192.168.168.135/

图片11.png
2021-4-26 14:52

备注:有警告是因为此证书是自己制作的,并没有得到浏览器的认可,但不影响访问和加密。

继续访问即可:
图片12.png
2021-4-26 14:52



Nginx在做了反向代理的情况下也可以使用SSL:
图片13.png
2021-4-26 14:52


图片14.png
2021-4-26 14:53






相关文章:
CentOS6_iptables
CentOS6_Nginx反向代理+Nginx版网站安全狗
CentOS6_Nginx基于域名的虚拟主机+反向代理+两个Tomcat

返回列表