Nginx 代理以及HTTPS (二)
一、HTTPS解析
https 加密
私钥
公钥
http 的握手 是确认网络是连通的。
https 的握手 是一个加密的过程 加密图
二、 使用Nginx 部署HTTPS 服务
1.证书生成命令(https://gist.github.com/Jokcy/5e73fd6b2a9b21c142ba2b1995150808) copy 里面的命令 在 Git上面运行
2.访问网站获得的命令
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -keyout localhost-privkey.pem -out localhost-cert.pem
3.在 git 上运行此命令
就会生成如下两个文件:
4. 启动 nginx 报错:bind() to 0.0.0.0:443 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions
这是由于其他进程占用了nginx 的端口。
解决办法:
运行 cmd, 输入netstat -aon|findstr "443"
找到 0.0.0.0:443,找到 PID,在任务管理器结束进程。 vmware-hostd.exe
5.成功启动Nginx
5.启动一个 nodejs 的服务:
然后再浏览器输入test,默认跳转https 服务。
2.配置 Nginx 代码
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;# 把http变为 https
server {listen 80 default_server;listen [::]:80 default_server;server_name test.com;return 302 https://$server_name$request_uri;}server {listen 443;server_name test.com;#开启https验证ssl on; #Nginx 1.5 以后 不需要 ssl on 直接删除这行代码即可(但是删除以后就不会出现https 服务了,所以还是不要删除)ssl_certificate_key ../certs/localhost-privkey.pem;ssl_certificate ../certs/localhost-cert.pem;location / {proxy_cache my_cache;proxy_pass http://127.0.0.1:8888;proxy_set_header Host $host;}
}
三、HTTP2的优势和Nginx配置HTTP2的简单实用
1.优势:
信道复用
分帧传输
Server Push
2.开启 http2 协议 仅仅支持在https协议。
效果图:
查看http 2 的push 服务端推送特性 chrome://net-internals/#events
server.js 代码:
const http = require('http')
const fs = require('fs')http.createServer(function (request, response) {console.log('request come', request.url)const html = fs.readFileSync('test.html', 'utf8')const img = fs.readFileSync('test.jpg')if (request.url === '/') {response.writeHead(200, {'Content-Type': 'text/html','Connection': 'keep-alive','Link': '</test.jpg>; as=image; rel=preload' //路径 格式 服务器加载方式})response.end(html)} else {response.writeHead(200, {'Content-Type': 'image/jpg','Connection': 'keep-alive' // or close})response.end(img)}}).listen(8888)console.log('server listening on 8888')
test.html 代码:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title>
</head>
<body><img src="/test.jpg" alt="">
</body>
</html>
test.jpg
.conf
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;server {listen 80 default_server;listen [::]:80 default_server;server_name test.com;return 302 https://$server_name$request_uri;
}server {listen 443 http2;server_name test.com;http2_push_preload on;ssl on;ssl_certificate_key ../certs/localhost-privkey.pem;ssl_certificate ../certs/localhost-cert.pem;location / {proxy_cache my_cache;proxy_pass http://127.0.0.1:8888; proxy_set_header Host $host; }
}
Nginx 代理以及HTTPS (二)相关推荐
- 阿里云个人站点基于nginx代理搭建https协议支持
阿里云个人站点基于nginx代理搭建https协议支持 准备工作 购买免费个人版dv证书 配置nginx 开放防火墙端口 检测是否成功 准备工作 1.个人服务器 2.安装了ssl_moudle的ngi ...
- 配置nginx代理实现https访问
配置nginx代理实现https访问 Google宣布从Chrome网络浏览器的下一个稳定版本(90)开始,将为地址栏中输入的所有URL网址默认选择HTTPS协议.这意味着未启用HTTPS的网站的打开 ...
- nginx正向代理转发https出现502
nginx正向代理转发https出现502 现象1 原因1 解决方案1 参考博客1 现象2 原因2 解决方案2 参考博客2 其他原因 现象1 nginx的error日志显示如下(xxx是替换过了真实信 ...
- Nginx学习笔记(二):反向代理
一:nginx 反向代理 Nginx 服务器的反向代理服务是其最常用的重要功能,由反向代理服务也可以衍生出很多与此相关的 Nginx 服务器重要功能,比如后面会介绍的负载均衡.本篇博客会先介绍 Ngi ...
- 二、Nginx 代理
一.Nginx 配置 二.Nginx 代理 三.Nginx 负载均衡 四.Nginx 性能调优 一.Nginx 代理 提高访问速度. 由于 目标主机 返回的数据,会存放在 代理服务器 的硬盘中. 因此 ...
- 通过Nginx代理机制下载微信二维码
文章目录 通过Nginx代理机制下载微信二维码 通过Nginx代理机制下载微信二维码 通过nginx代理机制,解决 前端 在页面中通过js直接下载微信二维码产生的跨域问题. location ^~ / ...
- nginx 代理https后,应用redirect https变成http --转
原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明 nginx配置https,tomcat正常http接受nginx转发. n ...
- 前后端分离系统使用Nginx代理https地址
记一次服务由http转成https的nginx配置问题,nginx基础的一些配置就不在这边说了. 使用了nginx的gzip压缩功能:用于提升用户访问前端页面的速度 http {include mim ...
- nginx代理tomcat,https
转载来源 : nginx代理tomcat,https https://www.jianshu.com/p/bdf8dc5b39b3 问题:nginx配置完https成功,但是nginx到tomcat的 ...
最新文章
- redissession有容量上限吗_空气炸锅值得买吗?
- 同时给两个变量值赋值
- Linux进程状态解析之R、S、D、T、Z、X
- DedeCms织梦发布文章时输入Tag标签逗号自动变成英文标点的方法
- web 资源管理器相关产品
- iOS linker command failed with exit code 1 (use -v to see invocation)多种解决方案汇总
- Shopify:删除版权信息 Powered by Shopify 在网站底部
- Unity2018新功能抢先预览 | Preset功能
- qpython能使用json吗l_[python] 详解Python在使用JSON时需要注意的编码问题
- 很多人都爱玩的lol..
- 4. 根据UDP端口号抓IPsec协议默认的500/4500端口报文
- Java LinkedHashMap类
- 【视频分享】尚硅谷Oracle视频教程
- 服务器数码管不显示,LED数码管不亮的原因及故障排查方法
- c++实现简单的qq连连看秒杀挂
- Java支付宝订单查询
- 怎么测试计算机运算能力,处理器运算能力测试_CPU_CPUCPU评测-中关村在线
- 简单脱壳教程笔记(2)---手脱UPX壳(1)
- 基于PHP+MySQL的服装购物商城
- 联发科MTK手机线刷错误代码信息解译以及解决方法大全