全站http 自动跳转 https
- 基于通信安全,全站在不影响用户访问的前提下实现 http 自动跳转 https
~]# vim /apps/nginx/conf/conf.d/rewrite.conf
server {
listen 443 ssl;
listen 80;
ssl_certificate /apps/nginx/certs/www.rookie.com.crt;
ssl_sertificate_key /apps/nginx/certs/www.rookie.com.key;
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
server_name www.rookie.com;
location / {
root /data/nginx/html/web;
index index.html;
if ( $scheme = http ) { # 不写条件判断,会导致来自 https 的访问进入死循环
rewrite / https://www.rookie.com permanent;
}
}
}
判断文件是否存在
location / {
root /data/nginx/html/home;
index index.html;
if (! -f $request_filename) {
#return 404 "error";
rewrite (.*) http://www.rookie.com/index.html;
}
}