0
点赞
收藏
分享

微信扫一扫

nginx http请求强转https 无www强转www服务 过百度https认证


文章目录

  • ​​1 介绍​​
  • ​​2 nginx.conf 配置​​
  • ​​2.1 http 转https​​
  • ​​2.2 https无www强转www​​
  • ​​3 过百度https认证​​

1 介绍

为了让网站个安全,我们通常会安装https证书,但是通常https部署后,https请求仍能访问,所以接下来我们要试下http强转https

2 nginx.conf 配置

2.1 http 转https

http://www.920z.net 转 https://www.920z.net
这里重点利用 return 301

server {
listen 80;
server_name www.920z.net;
return 301 https://$http_host$request_uri;
}

然后443端口的https监听配置好,即可完成强制转换。

2.2 https无www强转www

​​https://lgch.xyz/转https://www.lgch.xyz​​

# https没有www跳转www
server {
listen 443;
server_name lgch.xyz;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
return 301 https://www.lgch.xyz$request_uri;
}

3 过百度https认证

rewrite ^/(.*) https://www.lgch.xyz? permanent;

注意, 域名后面是?不是 $1,否则也会不通过



举报

相关推荐

0 条评论