场景:服务器F针对访问终端需要添加白名单操作,由到终端数量较多,所以用了一台代理服务器 P,在服务F中添加 服务器P IP地址的白名单,所有终端访问服务器P

由于我已经安装过 Nginx 所以只需要添加模块的配置,这里先说明 stream 四层代理的实现方式,(仅满足项目需要配置,其它配置项可百度参考相应的说明)

切换到安装目录下

[root@localhost nginx-1.12.2]# pwd
/usr/local/iron/nginx-1.12.2
[root@localhost nginx-1.12.2]#
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module
[root@localhost nginx-1.12.2]# make
[root@localhost sbin]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-no-strem
[root@localhost sbin]# cp /usr/local/iron/nginx-1.12.2/objs/nginx /usr/local/nginx/sbin/nginx
cp:是否覆盖"/usr/local/nginx/sbin/nginx"? y
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module
[root@localhost sbin]#

 

nginx.config

worker_processes  1;

events {
worker_connections 1024;
}

stream {
map $ssl_preread_server_name $name {
default backend;
# backend.example.com backend2;
}


upstream backend {
server ironfo.com:443;
# server 192.168.0.4:12345;
}

#upstream backend2 {
# server 192.168.0.1:12345;
# server 192.168.0.2:12345;
#}

server {
listen 8080;
proxy_pass $name;
ssl_preread on;
}
}

 

[root@localhost sbin]# /usr/local/nginx/sbin/nginx -s reload  重新加载配置文件

 

 

Nginx 配置 stream SSL 第四层 代理_nginx

 

 此时访问网站会提示不安全的连接

配置 hosts 文件(由于项目的特殊性,常不会这样的操作,没必要这么绕一圈)

192.168.1.1 为Nginx 服务器的IP

Nginx 配置 stream SSL 第四层 代理_服务器_02

 

 重新浏览器,可正常访问

 

Nginx 配置 stream SSL 第四层 代理_Nginx_03