【Nginx】将http升级到https并且同时支持http和https两种请求
2023-09-14 08:57:35 时间
一、如何将http升级到https
需要满足下面三个:
1.域名
2.nginx
3.SSL证书
一般第三方证书颁发机构下发的证书是收费的,一年好几千。
1) 从腾讯云申请免费的SSL证书,有效期一年,可申请多个
SSL 证书申请地址在这里: https://console.qcloud.com/ssl
申请过程几分钟就可以搞定,主要分两步
1.申请免费的证书,设置手动DNS验证
2.到域名对应的域名解析商处添加解析记录
下载申请好的域名,上传到服务器指定位置
2) nginx配置
2.1.使Nginx 支持 SSL
1)检查 Nginx 是否支持 SSL /usr/local/nginx/sbin/nginx -V configure arguments中是否有--with-http_ssl_module 如: nginx version: nginx/1.13.4 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --with-http_ssl_module 2) 若不支持,为nginx添加SSL 模块 进入nginx安装目录执行: ./configure --with-http_ssl_module 然后,注意不要make install make 3)备份原 Nginx 执行脚本 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old 4)将新版本 Nginx 编译脚本放到可执行文件目录下 cd objs/ cp nginx /usr/local/nginx/sbin/ 5)进行平滑升级 make upgrade
再次检查是否安装成功:
/usr/local/nginx/sbin/nginx -V
2.2.编辑Nginx配置文件
cd /usr/local/nginx/conf
vim nginx.conf
server { listen 443 ssl; server_name 你的域名; ssl_certificate 你的证书.crt; ssl_certificate_key 你的证书.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { proxy_pass http://127.0.0.1:8080; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
二、同时支持http和https两种请求
nginx配置新增server的配置
# http -> https server { listen 80; server_name 你的域名; rewrite ^(.*)$ https://$host$1 permanent; }
相关文章
- K8S学习笔记之docker registry使用http非https
- 使用 http-proxy 代理 HTTP 请求时遇到的 the requested url is invalid 错误消息
- Go HTTP 编程 | 01 - 使用 http 包创建 Web 服务器
- Go HTTP 编程 | 03 - 表单的输入与验证
- RPC 调用和 HTTP 调用的区别
- nginx转发https到http
- 字节一面:HTTP 常见的状态码有哪些?
- 访问 SAP 电商云 Storefront 时遇到的 HTTP 403 错误
- 服务器、客户端和http协议—互联网的原理
- HTTP隧道
- golang源码分析:http代理和https代理
- http强制跳到https
- 真正“搞”懂HTTP协议14之HTTP3
- 说一下HTTP服务的全过程及扩展问题整理
- 【Netty】使用 Netty 开发 HTTP 服务器 ( HTTP 请求过滤 )
- 淘汰的RTMP、HTTP-FLV、HLS直播技术,拥抱互联网直播的未来--WEBRTC、WEBSOCKET
- http和https区别?
- nginx同时使用(http)80和(https)443端口详解程序员
- python通过get方式,post方式发送http请求和接收http响应-urllib urllib2详解编程语言
- 部署Linux服务器,实现高效安全的HTTP通信(http服务器linux)
- 服务Linux 下监控HTTP服务的方法(linux监控http)
- Http接口调用示例教程详解编程语言
- https和http有何区别详解编程语言
- Linux安全协议:借助HTTPS保障信息安全(linux支持https)
- 服务器管理Linux中的HTTP服务器(linux中http)
- HTTP请求在Linux下的实现(http请求linux)
- HTTP 教程
- Linux快速搭建超强HTTP服务器(linux搭建http服务器)