Nginx Web环境同目录绑定多个域名且支持SSL方法
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

今天,蜗牛遇到一个网友需要将同网站目录绑定多个域名,且可以实现每个域名的SSL证书,也就是说都要实现HTTPS加密格式。项目是微擎管理系统,目的是希望给客户的演示域名并非主站的域名,而是临时的测试域名,根据他的说法是希望不要被人知道主域名,这样不容易被人投诉。
但是,辅助和临时域名希望与主站的数据一样。他开始提到是否可以用301方式实现,301肯定不可以实现,因为打开之后还是会跳转到主站的域名。他的主站是有HTTPS加密的,因为根据微信的政策,需要微擎等项目都要SSL证书支持HTTPS才可以运行。所以希望辅助域名也可以用到SSL证书。
开始我想远了,准备将所有数据和数据库信息都用增量备份的形式实现的,虽然可以实现,但是确实比较复杂没有必要。然后想到是否可以直接在Nginx配置文件中添加多个server模块实现。
文章目录
隐藏
第一、配置准备工作
第二、原始Nginx配置文件
第二、添加多域名配置文件
第一、配置准备工作2、备用域名需要申请自己的SSL证书。当然,如果我们不放心,还是先将服务器重要数据备份。
第二、原始Nginx配置文件server {
listen 443;
ssl on;
root /www/web/laobuluo_com/public_html;
server_name laobuluo.com www.laobuluo.com;
index index.html index.php index.htm;
ssl_certificate /www/wdlinux/nginx-1.8.1/conf/cert/laobuluo.com.pem;
ssl_certificate_key /www/wdlinux/nginx-1.8.1/conf/cert/laobuluo.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_per_server_ciphers on;
location ~ \\\\.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\\\\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
server {
listen 80;
root /www/web/laobuluo_com/public_html;
server_name laobuluo.com www.laobuluo.com;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location ~ \\\\.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\\\\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
这个客户主站的SSL证书也是我帮助配置的,上面就是原有的配置文件。注意域名这里我替换掉了。我们需要根据自己的来配置。
第二、添加多域名配置文件server {
listen 443;
ssl on;
root /www/web/itbulu_com/public_html;
server_name itbulu.com www.itbulu.com;
index index.html index.php index.htm;
ssl_certificate /www/wdlinux/nginx-1.8.1/conf/cert/itbulu.com.pem;
ssl_certificate_key /www/wdlinux/nginx-1.8.1/conf/cert/itbulu.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_per_server_ciphers on;
location ~ \\\\.php$ {
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
location ~ /\\\\.ht {
deny all;
}
location / {
try_files $uri @apache;
}
location @apache {
internal;
proxy_pass http://127.0.0.1:88;
include naproxy.conf;
}
}
这里我们需要添加一个新备用域名的server模块到配置文件中。同时需要将80端口中的server_name配置域名,加上新的域名。
server_name laobuluo.com www.laobuluo.com itbulu.com www.itbulu.com;
最后,重启Nginx可以生效,这时候蜗牛去打开新网址和主站老网站都可以打开HTTPS格式的。
猜你可能想看的VPS
- Rainbow Cloud→$30 月 E3-12XX 8G 内存 1T日本VPS[主机]
- AquaNX→圣何塞无限流量 VPS 月付 3.5 美元起 可选精品网 香港VPS[主机]
- 阿里云双 11 返场→企业认证用户 2 核 8G5M 云服务器 1140全球[VPS测评]
- IOFLOOD→$79 月-E3 1230v2 16GB 2x512G 全球[VPS测评]
- dedecms 后台无法登陆 dedecms 后台登陆跳转回登录页全球[VPS测评]
- 便宜 $20 年 1 核 512M 内存 10G 硬盘 1T 流量 1G全球[VPS测评]
- 宝塔面板 nginx 安装的 wordpress 或者 typecho 全球[VPS测评]
- jquery 打印插件 jqprint.js 使用教程全球[VPS测评]
- nat.bz→1500 元 月 2 核 4GB 内存 20GB 空间 不虚拟空间(主机)
- Domeny.pl→.pl .com.pl .edu.pl .site 全球[VPS测评]
- Mac 系统提示“pip install ” is failing wi全球[VPS测评]
- PuzCloud→103.2 元 季 1GB 内存 10GB 空间 50虚拟空间(主机)
- 腾讯云服务器限时秒杀,国内 香港,100%CPU 性能,2 核 4G 内香港VPS[主机]
- 新商家慎重-YonZy→66 元 年 512MB 内存 6GB SSD 虚拟空间(主机)
- xxmhost→57.2 元 月 1GB 内存 15GB SSD 空间 虚拟空间(主机)
- RangCloud 推出山东BGP NAT VPS全球[VPS测评]
- 如何在 CentOS 7 服务器上使用 yum命令安装 PHP7.2全球[VPS测评]
- 浅谈博客运营前、中、后期如何实现盈利全球[VPS测评]
- VPSslim-月付€2荷兰VPS 1核 1G 内存25G 空间 不限流虚拟空间(主机)
- Networkpresence-澳大利亚阿德莱德 2.15美元 月 2T全球[VPS测评]
- 又一跨境电商产业园落户!中山石岐签约引进16个项目全球[VPS测评]
- 2020年国外VPS哪个最好?教你学会选择国外VPS全球[VPS测评]
- 傲游主机:香港cn2高防云主机,159元/月/2核/2GB/40GB/2香港VPS[主机]
- 华纳云双十一钜惠活动:香港美国云服务器低至3.5折美国VPS[主机]
- 樊云:9折优惠,香港cn2 vps+(强制三网、50G高防);美国cn2美国VPS[主机]
- 情画数据:香港沙田CN2云服务器,2核/2G/5M带宽,年付200元香港VPS[主机]
- 华凯易佰同比扭亏跨境电商行业回暖H2旺季将至中报追踪全球[VPS测评]
- 酷锐云:香港安畅机房4H/4G/60G/20Mbps,45元/月;香港C香港VPS[主机]
- sugarhosts首推DECADE云服务器,香港云服务器,1核512M香港VPS[主机]
- edgeNAT:2021元旦vps促销_全场韩国/美国/香港VPS低至7韩国VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-143024.html











