NGINX SNI 配置:使用不同域名和证书
NGINX 基于 SNI(Server Name Indication)访问域名的配置如下:
- 编辑
nginx.conf文件,添加以下配置:
http {
...
server {
listen 443 ssl;
server_name example.com;
ssl_certificate '/path/to/example.com.crt';
ssl_certificate_key '/path/to/example.com.key';
location / {
...
}
}
server {
listen 443 ssl;
server_name sub.example.com;
ssl_certificate '/path/to/sub.example.com.crt';
ssl_certificate_key '/path/to/sub.example.com.key';
location / {
...
}
}
}
上面的配置中,分别配置了两个域名 example.com 和 sub.example.com,分别使用不同的 SSL 证书进行加密通信。
-
在 DNS 中配置好域名解析,将域名指向服务器的 IP 地址。
-
重启 NGINX 服务,使配置生效。
以上就是基于 SNI 访问域名的 NGINX 配置方法。通过这种方式,可以在同一个服务器上部署多个不同的网站,并使用不同的 SSL 证书进行加密通信,提高安全性和用户体验。
原文地址: https://www.cveoy.top/t/topic/lRvI 著作权归作者所有。请勿转载和采集!