Nginx rewrite 实例

2019-03-19  本文已影响0人  Alexander_Zz

全站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;
  }
}  
上一篇 下一篇

猜你喜欢

热点阅读