配置Nginx根据域名来源进行端口转发

Published: Tags: NGINX

之前笔者写了一篇「通过Nginx的端口转发提高加速器效率」的博文,现在补上额外配置。

stream {
    map $ssl_preread_server_name $domain_name {
          ssh.j2.com  ssh;
        mysql.j2.com  mysql;
             default  website;
    }
    
    upstream ssh     { server 172.17.12.1:22; }
    upstream mysql   { server 172.17.12.1:3306; }
    upstream website { server 172.17.12.1:80; }
    
    server { listen 443; ssl_preread on; proxy_pass $domain_name; }
}

访问方式如下:

# SSH
ssh -v root@ssh.j2.com
# MYSQL
mysql -u root -p -h mysql.j2.com
# HTTP
curl -s http://website.j2.com/phpinfo.php