ngx_http_rewrite_module模块:
将用户请求的URI基于PCRE regex所描述的模式进行检查,而后完成重定向替换
一、使用if判断,通过return,将http跳转到https
vim /etc/nginx/conf.d/test.conf
server {
listen 443 ssl;
listen 80;
server_name www.a.net;
root /data/site1/;
ssl_certificate /etc/nginx/ssl/www.a.net.crt;
ssl_certificate_key /etc/nginx/ssl/www.a.net.key;
ssl_session_cache shared:sslcache:20m;
ssl_session_timeout 10m;
access_log /var/log/nginx/a.net.log443 main;
location / {
if ( $scheme = http ){
return 301 https://www.a.net/;
}
}
}