Nginx 代理以及HTTPS (二)
一、HTTPS解析
https 加密
私钥
公钥
http 的握手 是确认网络是连通的。
https 的握手 是一个加密的过程 加密图
二、 使用Nginx 部署HTTPS 服务
1.证书生成命令(https://gist.github.com/Jokcy/5e73fd6b2a9b21c142ba2b1995150808) copy 里面的命令 在 Git上面运行
2.访问网站获得的命令
openssl req -x509 -newkey rsa: -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=: keys_zone=my_cache:10m; # 把http变为 https
server {
listen default_server;
listen [::]: default_server;
server_name test.com; return https://$server_name$request_uri; } server {
listen ;
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(, {
'Content-Type': 'text/html',
'Connection': 'keep-alive',
'Link': '</test.jpg>; as=image; rel=preload' //路径 格式 服务器加载方式
})
response.end(html)
} else {
response.writeHead(, {
'Content-Type': 'image/jpg',
'Connection': 'keep-alive' // or close
})
response.end(img)
} }).listen() 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=: keys_zone=my_cache:10m; server {
listen default_server;
listen [::]: default_server;
server_name test.com; return https://$server_name$request_uri;
} server {
listen 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 安装 和基础代理配置 假如 启动nginx 出现这个错误,可能是 iis服务被打开了,80端口被占用了. 需要如下操作: 用Nginx 配置一个test.com 的代理名称.配置ho ...
- nginx代理https站点(亲测)
nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...
- nginx 代理 https 后,应用变成 http
需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...
- 使用nginx代理后以及配置https后,如何获取真实的ip地址
使用nginx代理后以及配置https后,如何获取真实的ip地址 Date:2018-8-27 14:15:51 使用nginx, apache等反向代理后,如果想获取请求的真实ip,要在nginx中 ...
- Nginx代理MysqlCluster集群(二)
Nginx代理MySql集群本次实验采用nginx 版本1.12以上 集合了tcp代理功能只需在编译时明文开启指定的功能 --with-stream--prefix=/usr/local/ngin - ...
- CentOS 7.X下 -- 配置nginx正向代理支持https
环境说明: 本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623. ...
- NGINX之——配置HTTPS加密反向代理訪问–自签CA
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46695495 出于公司内部訪问考虑,採用的CA是本机Openssl自签名生成的,因 ...
- nginx 代理https后,应用redirect https变成http --转
原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...
- nginx 反向代理及 https 证书配置
nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...
随机推荐
- GIT配置多用户
在公司工作的时候有时候想提交一点代码到github上,然后一台电脑上就需要配置两个账号分别访问github和公司的gitlab 1. 分别生成两个key 为什么要生成两个key的原因我也不清楚,望路过 ...
- python 序列化和反序列化
概念 序列化: 将对象的状态信息转换为可以存储或传输的形式的过程.就是把对象转换成字符串的过程 反序列化: 把字符串转换成python可以识别的数据类型对象的过程 应用 #数据存储 #网络传输 模块 ...
- java 实现顺序结构线性列表
package com.ncu.list; /** * * 顺序结构线性列表 * * @author liuhao * */ public class SquenceList<T> { p ...
- spring揭秘 读书笔记 二 BeanFactory的对象注冊与依赖绑定
本文是王福强所著<<spring揭秘>>一书的读书笔记 我们前面就说过,Spring的IoC容器时一个IoC Service Provider,并且IoC Service Pr ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- UVA 11020 - Efficient Solutions(set)
UVA 11020 - Efficient Solutions 题目链接 题意:每个人有两个属性值(x, y).对于每个人(x,y)而言,当有还有一个人(x', y'),假设他们的属性值满足x' &l ...
- 计算机系统之汇编---IA32处理器数据格式及数据操作
计算机系统之汇编---IA32处理器数据格式及数据操作 IA32数据格式: Intel用术语"字"表示16位数据类型,因此.称32位数为"双字",称64位数为& ...
- hdu5371Hotaru's problem manacher算法
//给一个序列.让求其最大子序列 //这个序列由三段组成.第一段和第二段对称,第一段和第三段一样 //manacher算法求得p[i] //枚举第二段的起点和长度,得到结果 #include<c ...
- less11 属性合并
less //+ 合并以后,以逗号分割属性值 .mixin() { box-shadow+: inset 0 0 10px #555 ; } .myclass { .mixin(); box-shad ...
- 37.创建自定义的指令的限制使用 通过restrict 设置
转自:https://www.cnblogs.com/best/tag/Angular/ 1. 元素名 <runoob-directive></runoob-directive> ...