1.先创建一个配置文件
主要方便实验

可以将主配置文件下的location全部注释掉,方便观察
2.配置新配置文件
server{
listen 80;
listen 443 ssl;
ssl_certificate /usr/local/nginx/conf.d/ssl/www.kgc.com.crt;
ssl_certificate_key /usr/local/nginx/conf.d/ssl/www.kgc.com.key;
server_name www.cxk.com;
if ( $scheme = http ){
return 302 https://$host/$request_uri;
}
location / {
root /usr/local/nginx/html;
}
location /test {
root /usr/local/nginx/html;
}
}
重点为
if ( $scheme = http ){
return 302 https://$host/$request_uri;
}
大致意思为:如果是使用的http协议,就重新为https://IP地址/uri;
3访问测试


从http变为了https
再来访问http://192.168.174.104/test

