①. 首先你需要为你的服务器配置IPV6,只有拥有IPV6地址,你才可以使用。
任意服务器配置IPV6教程(由tech.cxthhhhh.com提供)
[Original] 手动给任意服务器配置 IPV6
任意服务器配置IPV6教程(由tech.cxthhhhh.com提供)
[Original] 手动给任意服务器配置 IPV6
②. 检查Nginx是否安装IPV6支持。【宝塔默认已开启–with-ipv6支持,此处可掠过】
SSH终端输入:[nginx -V],检查是否具有[–with-ipv6]输出,代表已经安装IPV6模块。
SSH终端输入:[nginx -V],检查是否具有[–with-ipv6]输出,代表已经安装IPV6模块。
③. 编辑网站配置文件。
查找
替换为
查找
listen 80;
listen 443 ssl http2;
替换为
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
提示配置出错的话,用不上那个443端口,把这两段删除。重载配置,重启就可以了。
listen 443 ssl http2;
listen [::]:443 ssl http2;
实测效果很不错。
重启Nginx
④. 现在你就可以通过IPV6访问你的网站了。
2.强制为我的站点启用SSL
①. 在网站配置文件新增以下内容
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
②.重启Nginx,清除浏览器缓存,你会发现HTTP(80)网站自动跳转到HTTPS(443)。
3. 我要将网站301重定向到带www的子域名
①. 在网站配置文件新增以下内容
*你需要修改cxthhhhh.com为你的域名
if ($host ~ '^cxthhhhh.com'){
return 301 https://www.cxthhhhh.com$request_uri;
}
*你需要修改cxthhhhh.com为你的域名
按照图片这样配置
②.重启Nginx,清除浏览器缓存,你会发现301重定向已经生效。