http重新为https

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://192.168.174.104查看结果

从http变为了https

再来访问http://192.168.174.104/test

相关推荐
小时前端4 天前
HTTPS 页面加载 HTTP 脚本被拦?同源代理来救场
前端·https
YuMiao4 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
不可能的是5 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
Jony_7 天前
高可用移动网络连接
网络协议
chilix7 天前
Linux 跨网段路由转发配置
网络协议
西岸行者9 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
gihigo19989 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
悠哉悠哉愿意9 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
别催小唐敲代码9 天前
嵌入式学习路线
学习
毛小茛9 天前
计算机系统概论——校验码
学习