nginx轉發https協議

1,需求

內網需要訪問github.com,並且是按照https://github.com這樣的訪問方式進行訪問。

因爲使用了npm install git+https://github.com/xxx/xxx.git之類的命令。

2,編譯nginx增加stream、ssl相關模塊

./configure --prefix=/etc/nginx/ 
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--with-stream
--with-stream_ssl_module
--with-stream_ssl_preread_module
--with-openssl=/path/to/openssl-1.0.2j
--with-pcre=/path/to/pcre-8.38

 

3,增加stream、ssl轉發配置

在nginx.conf中進行stream配置

stream {

  map $ssl_preread_server_name $backend_pool {
    github.com github;
    codeload.github.com codegithub;
  }

  upstream github{
    server github.com:443;
  }

  upstream codegithub{
    server codeload.github.com:443;
  }

  server{
    listen 443;
    ssl_preread on;
    proxy_pass $backend_pool;
    proxy_connect_timeout 15s;
    proxy_timeout 15s;
    proxy_next_upstream_timeout 15s;
  }

}

 

4,本地hosts文件配置

在中轉服務器端需要配置github.com相關的hosts解析;

在本地hosts文件中,直接將github.com解析到中轉服務器;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章