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解析到中轉服務器;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM