blog.zhuohua.store's Archiver

admin 发表于 2020-1-22 12:51

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

笺注:这是在 [url=http://blog.zhuohua.store/viewthread.php?tid=55&page=1&extra=#pid56]CentOS6_Tomcat+JDK+MySQL[/url] 的基础上做的


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


Nginx和Nginx版网站安全狗的安装可参考:[url=http://blog.zhuohua.store/viewthread.php?tid=302&extra=page%3D1]Oracle Linux6安装服务器安全狗、Nginx版网站安全狗[/url]
备注:Linux系统下,网站安全狗有Nginx版,但没有Tomcat版。



确认Tomcat正在运行:
[root@localhost ~]# elinks 127.0.0.1:8080
[attach]17054[/attach]


确认Nginx正在运行:
[root@localhost ~]# elinks 127.0.0.1
[attach]17055[/attach]


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



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

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

如下图:
[attach]17056[/attach]
注释:把对本机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]
[color=DarkRed]-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT [/color]
[color=DarkRed]#[/color]-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
[color=Purple]iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则:[确定]
iptables:正在卸载模块:[确定]
iptables:应用防火墙规则:[确定][/color]


查看防火墙的filter表的规则:
[color=Blue]iptables -nL[/color]
[attach]17057[/attach]



反向代理成功:(远程客户端只访问服务器的TCP 80端口)
http://192.168.168.135/
[attach]17058[/attach]


http://192.168.168.135/mm.jsp
[attach]17059[/attach]





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

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

相关的配置文件:
[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=[color=DarkRed]1[/color]  [color=DarkOrchid]#记录并拦截;默认是0,记录不拦截[/color]
NeedSendInterceptPageSQLAttack=0
SendAlert=1
UpdateUrl=http://www.safedog.cn/upload/configFile/sqlRule.dat
WhitePathCount=0

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


客户端远程测试:
http://192.168.168.135/[color=Blue]?order%20by[/color]
[attach]17060[/attach]

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













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

检测Nginx是否支持SSL:

[root@localhost ~]# [color=Blue]nginx -V[/color]
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: [color=Purple]--with-http_ssl_module[/color] --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

注释:有“[color=Purple]--with-http_ssl_module[/color]”就可以了。



Nginx的默认站点使用SSL:

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

如下图:
[attach]17061[/attach]


SSL证书的创建可参考:[url=http://blog.zhuohua.store/viewthread.php?tid=292&extra=page%3D1]Nginx基于域名的虚拟主机/域名重定向/访问控制/防盗链/SSL[/url]

上传SSL证书到服务器:
[attach]17062[/attach]


重启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表的规则:
[color=Blue]iptables -t filter -nL[/color]
[attach]17063[/attach]



客户端远程测试:
[color=DarkRed]https[/color]://192.168.168.135/

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

继续访问即可:
[attach]17065[/attach]


Nginx在做了反向代理的情况下也可以使用SSL:
[attach]17066[/attach]

[attach]17067[/attach]





相关文章:
[url=http://blog.zhuohua.store/viewthread.php?tid=169&extra=page%3D1]CentOS6_iptables[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=296&page=1&extra=#pid299]CentOS6_Nginx反向代理+Nginx版网站安全狗[/url]
[url=http://blog.zhuohua.store/viewthread.php?tid=303&page=1&extra=#pid306]CentOS6_Nginx基于域名的虚拟主机+反向代理+两个Tomcat[/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.