devops

Nginx无Https证书反向代理

2019-07-15  本文已影响0人  LoWang

起因

在我们托管服务器中,有闲置服务器需要给子公司使用,在内网为其搭建了虚拟服务器,通过公网Nginx反向代理的内网。内网的机器也有nginx,并使用https协议。

发现问题

SNI侦测

Nginx的SNI

Nginx的Stream

Nginx的ssl_preread

nginx.conf配置

worker_processes  1;
events {
    worker_connections  1024;
}

pid /var/run/nginx.pid;
stream {
  log_format proxy '$proxy_protocol_addr $remote_addr [$time_local] '
    '$protocol $status $bytes_sent $bytes_received '
    '$session_time "$upstream_addr" '
    '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

  access_log /usr/local/nginx/logs/access.log proxy;
  error_log /usr/local/nginx/logs/error.log info;

  map_hash_bucket_size 64;
  
  #https://cloud.tencent.com/developer/section/1259623
  map $ssl_preread_server_name $backend_pool {
    www.xuankejia.cn server_cn;
    www.xuankejia.com server_com;
    ~*.xuankejia.cn server_cn; #wildcard
    ~*.xuankejia.com server_com; #wildcard
    default server_baidu;
  }

  upstream server_cn{
    server 192.168.1.15:443;
  }

  upstream server_com{
    server 172.16.0.59:443;
  }
  
  upstream server_baidu{
    server 127.0.0.1:443;
  }
  
  server{
    listen 443;
    #https://cloud.tencent.com/developer/section/1259675
    ssl_preread on;
    proxy_pass $backend_pool;
    proxy_connect_timeout 15s;
    proxy_timeout 15s;
    proxy_next_upstream_timeout 15s;
  }
}

Nginx With stream_ssl_preread_module


centos>

yum -y install pcre-devel

check wether install or not:
dpkg -l | grep zlib

ubuntu>

gcc g++:
sudo apt-get install build-essential
sudo apt-get install libtool

ssl:
sudo apt-get install openssl libssl-dev

pcre:
sudo apt-get install libpcre3 libpcre3-dev

zlib:
sudo apt-get install zlib1g-dev

make -j4

> ------------

./configure  \
#--user=www  \
#--group=www  \
#--prefix=/usr/local/nginx  \
--with-http_ssl_module  \
--with-http_stub_status_module  \
--with-http_realip_module  \
--with-threads  \
--with-stream  \
--with-stream_ssl_preread_module  \
--with-stream_ssl_module


> --------------

BigVerion:

./configure --with-debug --prefix= --conf-path=conf/nginx.conf \
--pid-path=logs/nginx.pid --http-log-path=logs/access.log \
--error-log-path=logs/error.log --sbin-path=nginx.exe \
--http-client-body-temp-path=temp/client_body_temp \
--http-proxy-temp-path=temp/proxy_temp \
--http-fastcgi-temp-path=temp/fastcgi_temp \
--http-scgi-temp-path=temp/scgi_temp \
--http-uwsgi-temp-path=temp/uwsgi_temp --with-http_v2_module \
--with-http_realip_module --with-http_addition_module \
--with-http_sub_module --with-http_dav_module \
--with-http_stub_status_module --with-http_flv_module \
--with-http_mp4_module --with-http_gunzip_module \
--with-http_gzip_static_module --with-http_auth_request_module \
--with-http_random_index_module --with-http_secure_link_module \
--with-http_slice_module --with-mail --with-stream \
--with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module \
--with-threads --with-stream_ssl_preread_module


上一篇下一篇

猜你喜欢

热点阅读