应用服务器部署在内网中,须要和外网进行交互,可是中间间隔了两个区域,一个区域是业务子区,这个区域不能直接和互联网进行通讯,另外一个区域是DMZ区域能够和互联网进行通讯,所以咱们要和互联网进行通讯中间隔了两层网络。nginx
在业务子区放一台服务器安装nginx,并安装插件使其能够实现TCP的转发,而后DMZ区域放一台服务器安装squid实现正向代理。服务器
咱们的目的就是将应用层的数据转发到squid,实际上转发的数据使用的是TCP协议,nginx从1.9以后开始支持转发TCP协议,负责TCP转发的模块为stream,stream默认不安装的,须要手动添加参数:–with-stream nginx TCP代理模块配置文件以下网络
stream { ## TCP 代理日志格式定义 log_format tcp_proxy '$remote_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received ' '$session_time "$upstream_addr" ' '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"'; ## TCP 代理日志配置 access_log logs/tcp-access.log tcp_proxy; open_log_file_cache off; ## TCP 代理配置 server { listen 172.17.4.80:8091; #监听本机地址和端口,当使用keeplived的状况下使用keeplived VIP proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass 172.17.9.223:3128; #这里填写对端的地址 } }
#squid配置 squid是一个专门的正向代理软件其功能比较强大,能够限制网段和端口的出访,其具体配置以下:session
acl localnet src 172.17.9.0/24 # RFC1918 possible internal network acl localnet src 172.17.4.0/24 acl localnet src 55.66.8.0/24 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost manager http_access deny manager http_access allow localnet http_access allow localhost http_access allow all #容许全部的数据包经过 http_port 3128 coredump_dir /usr/local/squid/var/cache/squid refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320