一、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 (二)的更多相关文章

  1. NGINX 代理以及 HTTPS (一)

    一. Nginx 安装 和基础代理配置 假如 启动nginx 出现这个错误,可能是 iis服务被打开了,80端口被占用了. 需要如下操作: 用Nginx 配置一个test.com 的代理名称.配置ho ...

  2. nginx代理https站点(亲测)

    nginx代理https站点(亲测) 首先,我相信大家已经搞定了nginx正常代理http站点的方法,下面重点介绍代理https站点的配置方法,以及注意事项,因为目前大部分站点有转换https的需要所 ...

  3. nginx 代理 https 后,应用变成 http

    需求:nginx 代理 https,后面的 tomcat 处理 http 请求,sso 的客户端,重定向时需要带上 target,而这个 target 默认是 tomcat 的 http,现在需要把这 ...

  4. 使用nginx代理后以及配置https后,如何获取真实的ip地址

    使用nginx代理后以及配置https后,如何获取真实的ip地址 Date:2018-8-27 14:15:51 使用nginx, apache等反向代理后,如果想获取请求的真实ip,要在nginx中 ...

  5. Nginx代理MysqlCluster集群(二)

    Nginx代理MySql集群本次实验采用nginx 版本1.12以上 集合了tcp代理功能只需在编译时明文开启指定的功能 --with-stream--prefix=/usr/local/ngin - ...

  6. CentOS 7.X下 -- 配置nginx正向代理支持https

    环境说明: 本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623. ...

  7. NGINX之——配置HTTPS加密反向代理訪问–自签CA

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46695495 出于公司内部訪问考虑,採用的CA是本机Openssl自签名生成的,因 ...

  8. nginx 代理https后,应用redirect https变成http --转

    原文地址:http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.html 情况说明nginx配置https,tomcat正常http接受nginx转发.ngi ...

  9. nginx 反向代理及 https 证书配置

    nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...

随机推荐

  1. 紫书 例题8-5 UVa11054(等价转换)

    这道题用到了等价转换的思想 所有要运到a1的酒, 都要经过a2, 所以不如把a2的值改成a1+a2,然后依次以此类推. #include<cstdio> #include<cmath ...

  2. 【Henu ACM Round#24 B】Gargari and Bishops

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果写过n皇后问题. 肯定都知道 某个点(i,j)和它在同一条对角线上的点分别是i+j的值和i-j的值相同的点. 然后会发现选择的两 ...

  3. XML快速注释

    eclipse中编辑java或C/C++,python文件时,注释的快捷键均为 "CTRL + / ",编辑xml文件时,该快捷键无效. eclipse XML 注释:CTRL + ...

  4. zoj_3657,12年长春站c题,模拟

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

  5. 基于UDP的DDos反射放大攻击

    转自:https://www.us-cert.gov/ncas/alerts/TA14-017A Protocol Bandwidth Amplification Factor DNS 28 to 5 ...

  6. nyoj--46--最少乘法次数(数学+技巧)

    最少乘法次数 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 给你一个非零整数,让你求这个数的n次方,每次相乘的结果可以在后面使用,求至少需要多少次乘.如24:2*2=2 ...

  7. BZOJ 3503 高斯消元

    思路: 高斯消元就好啦 注意每个格子最多只能和4个相邻 所以是 n*m*n*m*5 的 并不会TLE //By SiriusRen #include <cstdio> #include & ...

  8. ip反查域名的详细信息(多种方法)

    不多说,直接上干货! 至于这里怎FQ,很简单,请见我下面的博客! kali 2.0安装 lantern(成功FQ) shadowsocks(简称SSFQ软件)步骤详解 FQ软件lantern-inst ...

  9. C语言基础-第六章

    数组和字符串 1.一维数组 数组当中最简单的数据 声明: 类型说明符 数组名[常量表达式] int a[3];说明a的长度为3,那么给a赋值的语句是:a={1,2,3}; 2.多维数组 2.1 二维数 ...

  10. [转]Adobe Creative Cloud 2015 下载 Adobe CC 2015 Download

    Adobe Creative Cloud 2015 下载   Adobe 宣布 Creative Cloud 设计套件全线更新! Adobe CC 2015新功能包括: – Premiere Pro ...