全球主机交流论坛
标题:
如何让http自动跳转到https
[打印本页]
作者:
天蚕土豆
时间:
2018-3-17 13:47
标题:
如何让http自动跳转到https
我的域名已经申请了ssl,那么在虚拟空间里面如何设置,才可以让http自动跳转到https呢?谢谢
作者:
cnmeimei
时间:
2018-3-17 13:49
301
301
作者:
naiji
时间:
2018-3-17 13:57
apache虚拟主机的话修改 .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ http s://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
复制代码
http s去掉空格
作者:
我不是你的
时间:
2018-3-17 14:53
naiji 发表于 2018-3-17 13:57
apache虚拟主机的话修改 .htaccess:
我比较喜欢用nginx
作者:
imes
时间:
2018-3-17 14:59
提示:
作者被禁止或删除 内容自动屏蔽
作者:
天蚕土豆
时间:
2018-3-17 15:09
naiji 发表于 2018-3-17 13:57
apache虚拟主机的话修改 .htaccess:
是放到 public_html 目录吗
作者:
naiji
时间:
2018-3-17 15:17
你要全站跳转的话就放在public_html
作者:
doio
时间:
2018-3-17 15:27
启用 HSTS
这是我的部分 nginx 配置
if ($scheme != "https") {
return 301 https://$host$request_uri;
}
复制代码
提取自 certbot
然后加了这个 header:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
复制代码
作者:
花猫
时间:
2018-3-17 15:33
元老问这样的问题合适吗?
作者:
天蚕土豆
时间:
2018-3-17 15:37
naiji 发表于 2018-3-17 15:17
你要全站跳转的话就放在public_html
成功,谢谢你
作者:
Giine
时间:
2018-3-17 15:48
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;
}
}
复制代码
欢迎光临 全球主机交流论坛 (https://loc.mjj8.eu.org/)
Powered by Discuz! X3.4