VPS侦探论坛

 找回密码
 注册
查看: 4689|回复: 3

利用meta实现http到https的强制跳转 (省服务器资源)

[复制链接]
发表于 2015-12-9 02:59:43 | 显示全部楼层 |阅读模式

不论是利用nginx伪静态重写,还是利用nginx497 都会相当耗费服务器资源。

下面讲述一种相对省服务器资源的方式:

1.首先建立一个index.html (由于主机拦截,代码只能贴成图片,你可查看 http://zuohuadong.lofter.com/post/24231d_931e51a)

2.若网站目录为 /home/wwwroot/www.ibenchu.com  在网站目录下新建 meta目录 将index.html放进去

3.配置nginx主机conf (一般在/usr/local/nginx/conf/vhost)
  1. server
  2.     {
  3.         listen 80;
  4.                 server_name www.ibenchu.com;
  5.                 location / {  
  6.                 #index.html放在虚拟主机监听的根目录下  
  7.         root /home/wwwroot/www.ibenchu.com/meta;  
  8.     }  
  9.         #将404的页面重定向到https的首页  
  10.     error_page  404 https://www.ibenchu.com/;
  11.         }
  12. server
  13.     {
  14.                 listen 443 ssl http2;
  15.         #listen [::]:443 ssl http2;
  16.                 ssl_certificate /etc/letsencrypt/live/www.ibenchu.com/fullchain.pem;
  17.         ssl_certificate_key /etc/letsencrypt/live/www.ibenchu.com/privkey.pem;
  18.         #listen [::]:80;
  19.         server_name www.ibenchu.com;
  20.         index index.html index.htm index.php default.html default.htm default.php;
  21.         root  /home/wwwroot/www.ibenchu.com;

  22.         include dayin.conf;
  23.         #error_page   404   /404.html;
  24.         include enable-php.conf;

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

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

  33.         access_log off;
  34.     }
复制代码
改掉www.ibenchu.com即可,伪静态 修改 dayin.conf

以上配置文件需要根据具体情况  酌情修改
如果主机不支持https 或者 不支持 http2 请看:https://bbs.vpser.net/thread-13009-1-1.html

此方法占用服务器资源少,问题在于 访问 http://xxx.com/sss 时 会被直接跳转到 https://xxx.com

[ 本帖最后由 依剑听雨 于 2015-12-9 03:31 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-12-9 10:19:11 | 显示全部楼层


用这个还不如直接用HSTS吧
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2015-12-9 13:06:15 | 显示全部楼层

回复 2# 的帖子


HSTS 只能chrome浏览器 用户端进行设置么?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-12-9 16:39:27 | 显示全部楼层

回复 3# 的帖子




HSTS是强制的不需要用户设置,只是服务器端需要加Strict-Transport-Security字段

https://www.vpser.net/build/letsencrypt-free-ssl.html 里有说明

ie11以上支持,chrome、firefox、safari等主流版本早已经支持
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 15:20 , Processed in 0.026251 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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