VPS侦探论坛

 找回密码
 注册
查看: 3824|回复: 5

单IP下多域名开启SSL问题

[复制链接]
发表于 2018-2-24 12:03:09 | 显示全部楼层 |阅读模式

请问下军哥,我在一个 IP 上绑了 2 个域名,在给他们先后开启 SSL 后,先前开启 SSL 的域名会跳转到新开启 SSL 的域名,如果我清空新开启 SSL 域名对应的 conf 文件,先前开启 SSL 的域名就能正常访问。VPS 是 CentOS 6 x64,lnmp 用的是 1.4 版本,确认 SNI 是启用的,按理说是支持单 IP 多域名 SSL 的。但是这个跳转问题困扰了我好几天,麻烦军哥指教下,谢谢。
下面贴上我 2 个域名对应的 conf(网站信息以 a,b 代替)

域名 a 的 conf:

server
{
listen 443 ssl;   #lnmp1.3+版本默认支持http2,可以加上http2,lnmp1.2版本默认支持spdy,可以加上spdy
server_name www.a.com;     ##这里是你的域名
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.a.com;            #网站目录
ssl_certificate /etc/letsencrypt/live/www.a.com/fullchain.pem;    #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/www.a.com/privkey.pem;   #前面生成的密钥,改一下里面的域名就行
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

include wordpress.conf;  #这个是伪静态根据自己的需求改成其他或删除
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;     #lnmp 1.0及之前版本替换为include fcgi.conf;
#include pathinfo.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log off;
}

server
{
listen 80;
server_name www.a.com a.com;
        location /.well-known/    #这段在续期前还需要在nginx配置下,80端口的虚拟主机上需要添加上,不加的话会无法验证的

{
        add_header Content-Type 'text/plain;';
        root /home/wwwroot/www.a.com; #网站目录

}

        location /

{
        return 301 https://www.a.com$request_uri;

}
}



域名 b 的 conf:

server
{
listen 443 ssl;   #lnmp1.3+版本默认支持http2,可以加上http2,lnmp1.2版本默认支持spdy,可以加上spdy
server_name www.b.com;     ##这里是你的域名
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.b.com;            #网站目录
ssl_certificate /etc/letsencrypt/live/www.b.com/fullchain.pem;    #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/www.b.com/privkey.pem;   #前面生成的密钥,改一下里面的域名就行
ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

include wordpress.conf;  #这个是伪静态根据自己的需求改成其他或删除
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;     #lnmp 1.0及之前版本替换为include fcgi.conf;
#include pathinfo.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

access_log off;
}

server
{
listen 80;
server_name www.b.com b.com;
        location /.well-known/    #这段在续期前还需要在nginx配置下,80端口的虚拟主机上需要添加上,不加的话会无法验证的

{
        add_header Content-Type 'text/plain;';
        root /home/wwwroot/www.b.com; #网站目录

}

        location /

{
        return 301 https://www.b.com$request_uri;

}
}
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2018-2-24 16:03:38 | 显示全部楼层


贴出的配置文件没有问题,按反馈必读要求 自己测试nginx配置文件看一下
1.4的有自动工具不需要手动写配置文件
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2018-2-24 16:44:56 | 显示全部楼层

回复 2# 的帖子


执行 /usr/local/nginx/sbin/nginx -t
返回显示没问题。。。

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2018-2-25 08:47:58 | 显示全部楼层



目前已有的信息看无法判断
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2018-11-14 12:10:58 | 显示全部楼层

www.a.com/fullchain.pem;    #前面生成的证书,改一下里面的域名就行


证书里面还可以改名的吗?
要怎么改?
那样是不是就只要申请一次通配符ssl后不用多次申请个别二级域名ssl了?

军哥运维代购:http://shop63846532.taobao.com/

发表于 2018-11-14 15:50:23 | 显示全部楼层

回复 5# 的帖子


生成的证书是什么名字就用什么名字
所有该域名的二级域名都用这个通配符证书就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-3-19 13:00 , Processed in 0.027310 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表