服务器 
首页 > 服务器 > 浏览文章

nginx http重定向https配置说明

(编辑:jimmy 日期: 2025/2/27 浏览:3 次 )

nginx http重定向https配置说明

现在什么苹果,谷歌浏览器请求地扯基本都要求使用https了,如何把原来的http协议重定向到https中呢,这里我们可以使用http反向代理软件nginx。

使用

安装

yum install nginx -y

配置

cat /etc/nginx

server {
 listen 80;
 server_name dounine.com www.dounine.com;
 return  301 https://www.dounine.com$request_uri;
}
server {
 listen 443;
 server_name dounine.com dounine.com;
 return  301 https://www.dounine.com$request_uri;
}
server {
 listen 443;
 server_name www.dounine.com;
 ssl on;
 ssl_certificate /etc/nginx/dounine.crt;
 ssl_certificate_key /etc/nginx/dounine.key;

 location / {
 client_max_body_size 20m;
 proxy_pass http://127.0.0.1:8080;
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }
}

以上配置可将www.dounine.com、dounine.com与https://dounine.com 重定向至https://www.dounine.com地扯中。

注意

记得将防火墙的80与443端口打开。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:linux vps服务器常用服务iptables策略
下一篇:linux下使用Docker和OSS轻松搭建ownCloud专属网盘(网盘关闭不用怕)
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。