Nginx实现http自动跳转到https
时间:2025-12-13 18:30:04|栏目:其它服务器|点击: 次
https是更安全的http,通过http自动跳转https,可以更便于用户使用web。
有几下几个方法可以完成跳转:
1.打开http和https的server,让http跳转到https
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate certificate_file_path;
ssl_certificate_key certificate_key_file_path;
...
}
2.不打开http的server,直接在https的server里完成跳转,以下三种方式都可以
server {
if ($server_port = 80 )
#if ($scheme = http )
#if ($ssl_protocol = "")
{
return 301 https://$host$request_uri;
}
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate certificate_file_path;
ssl_certificate_key certificate_key_file_path;
...
}
您可能感兴趣的文章
- 01-06nginx从安装到配置详细说明(安装,安全配置,防盗链,动静分离,配置 HTTPS,性能优化)
- 01-06Nginx性能优化之Gzip压缩设置详解(最大程度提高页面打开速度)
- 01-06Linux系统 Centos7.4手动在线升级到Centos7.7
- 01-06详解nginx安装过程并代理下载服务器文件
- 01-06shell脚本根据进程查找指定容器的方法
- 01-06微服务架构拆分策略详解
- 01-06使用 Apache Dubbo 实现远程通信(微服务架构)
- 01-06微服务架构之服务注册与发现功能详解
- 01-06使用Zabbix 5.4.3监控IPMI的方法
- 01-06微服务架构之服务注册与发现实践示例详解






