Nginx为同主机配置Https多域名
前面,我有提到nginx多网站配置,以及nginx配置https.但是在windows下面同主机配置多Https域名暂未提及,那么这次正好遇到这个场景。

前言
最近在做一个私活,因为老板考虑到节约成本,就只有一台2核4G的windows主机,可是现在是要独立出来多个微信小程序,故会涉及到多个应用。当然我也以才用nginx强大的location配置功能转发到不同的目录这也是可以实现的。但是感觉不是很优雅,所以还是使用强大的Server模块吧。
下载Nginx
windows使用nginx很简单,直接下载官方编译好的即可(如果自己来编译的话,操作还是有些繁琐).下载nginx的zip压缩包,如果想使用nginx+lua的话,那么就去下载OpenResty吧。
配置Nginx
首先肯定是去域名注册商去下载nginx的SSL证书,然后把我们的证书放在nginx的conf目录下。接下来就是编辑我们的nginx.conf配置文件。配置如下:
server {
listen 443 ssl;
server_name xxxxx.baoqipai.com;
ssl_certificate cert/xxxxx.baoqipai.com.pem;
ssl_certificate_key cert/xxxxx.baoqipai.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:8002;
}
}
server {
listen 443 ssl;
server_name admin.xxxxx.nationallab.cn;
ssl_certificate cert/admin.xxxxx.nationallab.cn.pem;
ssl_certificate_key cert/admin.xxxxx.nationallab.cn.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:8001;
}
}
server {
listen 443 ssl;
server_name host.xxxxx.nationallab.cn;
ssl_certificate cert/host.xxxxx.nationallab.cn.pem;
ssl_certificate_key cert/host.xxxxx.nationallab.cn.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://127.0.0.1:8001;
}
}
启动nginx,解析域名,此时不出意外应该可以正常访问了。
遇到的问题
这里有个会有一个小问题,会报could not build server_names_hash, you should increase server_names_hash_bucket_size: 32,这是因为server配置中server_name的值过长导致,http://nginx.org/en/docs/http/server_names.html提到修改server_names_hash_bucket_size的值:
http {
server_names_hash_bucket_size 64;
…
那么
server_names_hash_bucket_size的默认值是多少呢?
在官网文档中有提到:
Syntax: server_names_hash_bucket_size size;
Default: server_names_hash_bucket_size 32|64|128;
Context: http
Sets the bucket size for the server names hash tables. The default value depends on the size of the processor’s cache line. The details of setting up hash tables are provided in a separate document.
相关推荐
-
「nginx」十、nginx的location配置详解2026-07-04 00:51:45 -

最清晰的mysql体系架构图 ,助你深度掌握MySQL开发管理,赢在大数据时代
最清晰的mysql体系架构图 ,助你深度掌握MySQL开发管理,赢在大数据时代2026-07-04 00:21:47 -
PHP读取Excel内的图片2026-07-03 00:07:41 -
mysql:Otter跨机房数据同步(单向)2026-07-03 00:02:48 -

在windows10系统下搭建IIS+PHP+MYSQL+phpMyAdmin服务器运行环境
在windows10系统下搭建IIS+PHP+MYSQL+phpMyAdmin服务器运行环境2026-07-02 00:15:08