一 https的sni配置方法

http {
       }
       server {
               listen 443 ssl;
               server_name test1.www.local test1.tls.local;
               ssl_certificate /root/sni/sni_test1.cer;
               ssl_certificate_key /root/sni/sni_test1.key;
               location / {
                       root /data/www;
               }
       }
       server {
               listen 443 ssl;
               server_name test2.www.local test2.tls.local;
               ssl_certificate /root/sni/sni_test2.cer;
               ssl_certificate_key /root/sni/sni_test2.key;
               location / {
                       root /data/www;
               }
       }
       server {
               listen 443 ssl;
               server_name test3.www.local test3.tls.local;
               ssl_certificate /root/sni/sni_test3.cer;
               ssl_certificate_key /root/sni/sni_test3.key;
               location / {
                       root /data/www;
               }
       }
}

二 https的sni配置方法

http {
       #map \$server_name \$sni_string {
       map \$ssl_server_name \$sni_string {
               test1.www.local test1;
               test2.www.local test2;
               test3.www.local test3;
       #      default xxx;
       }
       server {
               listen 443 ssl;
               ssl_certificate /data/sni/sni_\${sni_string}.cer;
               ssl_certificate_key /data/sni/sni_\${sni_string}.key;
               location / {
                       root /data/www;
               }
       }
}

三 tls的sni配置方法

stream {
       upstream test {
               server 127.0.0.1:50001;
       }

map \$ssl_server_name \$sni_string {
               test1.www.local test1;
               test2.www.local test2;
               test3.www.local test3;
               default test1;
       }

server {
               listen 444 ssl;
               ssl_certificate /data/sni/sni_\${sni_string}.cer;
               ssl_certificate_key /data/sni/sni_\${sni_string}.key;
               proxy_pass test;
       }
}

四 复合情况下sni的配置方法

复合情况是指,多个server使用了相同的server name,又需要配置不同的证书文件时。

使用map定义多个不同的变量映射的方法,可以支持多个server的情况,如下,分别定义了两个变量 $sni_string 与 $sni_string445

用来处理不同的server。

stream {
       upstream test {
               server 127.0.0.1:50001;
       }

map \$ssl_server_name \$sni_string {
               test1.www.local test1;
               test2.www.local test2;
               test3.www.local test3;
               default test1;
       }
       map \$ssl_server_name \$sni_string445 {
               test1.www.local test4451;
               test2.www.local test4452;
               test3.www.local test4453;
               default test4451;
       }
       server {
               listen 444 ssl;
               ssl_certificate /data/sni/sni_\${sni_string}.cer;
               ssl_certificate_key /data/sni/sni_\${sni_string}.key;
               proxy_pass test;
       }
       server {
               listen 445 ssl;
               ssl_certificate /data/sni445/sni_\${sni_string445}.cer;
               ssl_certificate_key /data/sni445/sni_\${sni_string445}.key;
               proxy_pass test;
       }
}

[author: classic_tong, date: 20190925] 

最新文章

  1. Git忽略.gitignore规则不生效的解决办法
  2. python base64的加密与解密
  3. 通过代码自定义cell(cell的高度不一致)
  4. session 实现登录功能注意事项
  5. 一个短小的JS函数,用来得到仅仅包含不重复元素的数组
  6. java学习___File类的查看和删除
  7. [C#]6.0新特性浅谈
  8. tcp netstat用法 TIME_WAIT状态解析 MTU以及MSS
  9. Java类加载器的工作原理
  10. 【翻译】使用Sencha Touch开发Google Glass应用程序
  11. 编程心法 之什么是MVP What is MVP development?
  12. plus.webview更新上一个页面的信息
  13. mac 安装protobuf,并编译为java,c++,python
  14. 【APUE | 03】文件I/O
  15. Web界面实现数据库增删改查过程
  16. [视频]K8飞刀 shellcode loader演示教程
  17. python脚本计算斐波那契数列
  18. 机器学习实战(一)k-近邻算法
  19. php常量的实现
  20. mathematical method

热门文章

  1. spring cloud Eureka server 问题 Spring Cloud java.lang.TypeNotPresentException
  2. SDN实验---Ryu的安装
  3. Java通过行为参数化传递代码
  4. linux广播
  5. js scheme 打开手机app的方法
  6. [LeetCode] 163. Missing Ranges 缺失区间
  7. LeetCode,3. 无重复字符的最长子串
  8. .NET(C#)有哪些主流的ORM框架,SqlSugar,Dapper,EF还是...
  9. 树莓派插入U盘自动拷贝系统日志到U盘或通过U盘升级程序
  10. spring security实现记住我下次自动登录功能