HSTS域名更换实例

新入手了its0k.com,原来的alair.cn还继续使用

在这里需要将alair.cn重定向到its0k.com

第一次只是将nginx配置文件中的alair.cn全部替换为its0k.com,通过its0k.com浏览新站完全没问题

但是试着从alair.cn跳转浏览新站,浏览器出现了证书安全告警,告警具体原因为证书未包含alair.cn域名,我才想起来旧域名alair.cn已经添加进了HSTS列表,因此不能简单的只为新域名签名,而是需要证书签名时包含新旧两个域名。

重新签名了证书,包含以下四个域名

its0k.com www.its0k.com alair.cn www.alair.cn

以下为更改完成后的nginx配置文件,请注意名相关的部分

server {
listen 443 ssl http2;

ssl_certificate     /root/ssls/its0k.crt;
ssl_certificate_key /root/ssls/its0k.key;

ssl_session_timeout 60m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
ssl_prefer_server_ciphers on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_dhparam /etc/ssl/certs/dhparam.pem;

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options "DENY";

ssl_stapling on;
ssl_stapling_verify on;

resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;

server_name its0k.com www.its0k.com alair.cn www.alair.cn;
access_log off;
index index.html index.htm;
include /usr/local/nginx/conf/rewrite/ps.conf;
root /data/wwwroot/its0k.com/compiled;
error_page 403 404 500 503 505 = https://its0k.com/404;
if ($host != its0k.com) {
		rewrite ^/(.*)$ $scheme://its0k.com/$1 permanent;
		}

location ~ .*\.(gif|svg|jpg|jpeg|png|bmp|swf|flv|ico)$ {
	expires 30d;
	access_log off;
	}
location ~ .*\.(js|css)?$ {
	expires 7d;
	access_log off;
	}
}
server {
listen 80;
server_name www.its0k.com its0k.com alair.cn www.alair.cn;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
rewrite ^/(.*) https://its0k.com/$1 permanent;
}

至此域名替换完成!

发布于