如何让http自动跳转到https
我的域名已经申请了ssl,那么在虚拟空间里面如何设置,才可以让http自动跳转到https呢?谢谢 apache虚拟主机的话修改 .htaccess:[*]
[*] RewriteEngine On
[*]
[*] RewriteCond %{HTTPS} off
[*] RewriteRule ^(.*)$ http s://%{HTTP_HOST}%{REQUEST_URI}
[*]
[*]复制代码
http s去掉空格 301
301
naiji 发表于 2018-3-17 13:57
apache虚拟主机的话修改 .htaccess:
我比较喜欢用nginx
lol.gif
naiji 发表于 2018-3-17 13:57
apache虚拟主机的话修改 .htaccess:
是放到 public_html 目录吗 你要全站跳转的话就放在public_html 启用 HSTS
这是我的部分 nginx 配置
[*] if ($scheme != "https") {
[*]
[*] return 301 https://$host$request_uri;
[*] }复制代码
提取自 certbot
然后加了这个 header:
[*]add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;复制代码 元老问这样的问题合适吗?
lol.gif
naiji 发表于 2018-3-17 15:17
你要全站跳转的话就放在public_html
成功,谢谢你[*]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.8valid=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;
[*] }
[*]}复制代码
页:
[1]