使用nginx實現基於tcp協議的https協議多域名指向的分別轉發功能


零、環境

os:centos8 阿里雲

kernel:Linux ${hostname} 4.18.0-80.11.2.el8_0.x86_64 #1 SMP ${time} x86_64 x86_64 x86_64 GNU/Linux

nginx:nginx-1.17.5

一、編譯安裝nginx

由於nginx插件參數眾多,建議編譯安裝

安裝過程見https://www.cnblogs.com/mangoVic/p/8359864.html

注意須裝插件--with-stream 和 --with-stream_ssl_preread_module


二、配置

現有兩個不同目的地的https協議的域名,使用一個nginx進行轉發,一個域名是xxxxxx.com,另一個是yyyyyy.com

 

map $ssl_preread_server_name $backend_pool {
    xxxxxx.com    xxx;
    yyyyyy.com    yyy;
}
upstream xxx{
    server xxxxxx.com:443;
}
upstream yyy{
    server yyyyyy.com:443;
}
server {
    listen 443;
    ssl_preread on;
    resolver 8.8.8.8;
    proxy_pass $backend_pool;
    proxy_connect_timeout 15s;
    proxy_timeout 15s;
    proxy_next_upstream_timeout 15s;
    error_log /var/log/nginx/error-tcp_xxxxxx-yyyyyy.com.log info;
    access_log /var/log/nginx/access-tcp_xxxxxx-yyyyyy.com.log proxy;
}

三、格式測試

nginx -t
nginx

四、配置host

客戶端需要將域名指向到轉發機

#vi /etc/hosts
111.111.111.111 xxxxxx.com
111.111.111.111 yyyyyy.com

 

五、連通性測試

telnet proxy 443

六、客戶端直接訪問域名

curl https://xxxxxx.com

 


免責聲明!

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



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