找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 83|回复: 8

如何让http自动跳转到https

[复制链接]

13

主题

270

回帖

599

积分

高级会员

积分
599
发表于 2018-3-17 13:47:48 | 显示全部楼层 |阅读模式
我的域名已经申请了ssl,那么在虚拟空间里面如何设置,才可以让http自动跳转到https呢?谢谢
回复

使用道具 举报

9

主题

24

回帖

81

积分

注册会员

积分
81
发表于 2018-3-17 13:57:03 | 显示全部楼层
apache虚拟主机的话修改 .htaccess:
[ol]
  • [I]
  •     RewriteEngine On
  •     RewriteCond %{HTTPS} off
  •     RewriteRule ^(.*)$ http s://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • [/I][/ol]复制代码

    http s去掉空格
  • 回复

    使用道具 举报

    57

    主题

    1058

    回帖

    2321

    积分

    金牌会员

    积分
    2321
    发表于 2018-3-17 13:49:03 | 显示全部楼层
    301
    301
    回复

    使用道具 举报

    7

    主题

    89

    回帖

    213

    积分

    中级会员

    积分
    213
    发表于 2018-3-17 14:53:51 | 显示全部楼层

    naiji 发表于 2018-3-17 13:57

    apache虚拟主机的话修改 .htaccess:

    我比较喜欢用nginx

    回复

    使用道具 举报

    13

    主题

    270

    回帖

    599

    积分

    高级会员

    积分
    599
     楼主| 发表于 2018-3-17 13:57:00 | 显示全部楼层

    naiji 发表于 2018-3-17 13:57

    apache虚拟主机的话修改 .htaccess:

    是放到 public_html 目录吗
    回复

    使用道具 举报

    9

    主题

    24

    回帖

    81

    积分

    注册会员

    积分
    81
    发表于 2018-3-17 14:59:18 | 显示全部楼层
    你要全站跳转的话就放在public_html
    回复

    使用道具 举报

    2

    主题

    28

    回帖

    70

    积分

    注册会员

    积分
    70
    发表于 2018-3-17 15:09:59 | 显示全部楼层
    启用 HSTS
    这是我的部分 nginx 配置
    [ol]
  •         if ($scheme != "https") {
  •                 return 301 https://$host$request_uri;
  •                 }[/ol]复制代码


    提取自 certbot

    然后加了这个 header:
    [ol]
  • add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;[/ol]复制代码
  • 回复

    使用道具 举报

    72

    主题

    187

    回帖

    604

    积分

    高级会员

    积分
    604
    发表于 2018-3-17 13:57:00 | 显示全部楼层
    元老问这样的问题合适吗?

    回复

    使用道具 举报

    0

    主题

    1

    回帖

    4

    积分

    新手上路

    积分
    4
    发表于 2018-3-17 15:17:12 | 显示全部楼层

    naiji 发表于 2018-3-17 15:17

    你要全站跳转的话就放在public_html

    成功,谢谢你[ol]
  • server {
  •         server_name gov.cn;
  •         listen   443 ssl http2;
  •         ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  •             ssl_certificate /etc/letsencrypt/live/gov.cn/fullchain.pem; # managed by Certbot
  •             ssl_certificate_key /etc/letsencrypt/live/gov.cn/privkey.pem; # managed by Certbot
  •         ssl_session_cache        shared:SSL:10m;
  •         ssl_session_timeout      60m;
  •         ssl_session_tickets      on;
  •         ssl_stapling             on;
  •         ssl_stapling_verify      on;
  •         resolver                 8.8.4.4 8.8.8.8  valid=300s;
  •         resolver_timeout         10s;
  •         root /var/www/gov/public;
  •         index index.html index.php index.htm;
  •         location / {
  •                 try_files $uri $uri/ /index.php?$args;
  •         }
  •         client_max_body_size    4m;
  •         access_log /var/log/nginx/elsenow.log;
  •         error_log /var/log/nginx/error.elsenow.log;
  •         error_page 404 /404.html;
  •         error_page 500 502 503 504 /50x.html;
  •         location = /50x.html {
  •                 root /usr/share/nginx/html;
  •         }
  •         location ~ \.php$ {
  •                 try_files $uri /index.php =404;
  •                 fastcgi_split_path_info ^(.+\.php)(/.+)$;
  •                 fastcgi_pass 127.0.0.1:9000;
  •                 fastcgi_index index.php;
  •                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  •                 include fastcgi_params;
  •         }
  • }
  • server {
  •         listen 80;
  •         server_name gov.cn www.gov.cn;
  •         location / {
  •                 rewrite ^/(.*)$ https://gov.cn/$1 permanent;
  •         }
  • }[/ol]复制代码
  • 回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-2-23 07:52 , Processed in 0.023055 second(s), 8 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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