惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Secure Thoughts
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Security Latest
Security Latest
TaoSecurity Blog
TaoSecurity Blog
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
H
Hacker News: Front Page
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
AWS News Blog
AWS News Blog
AI
AI
G
GRAHAM CLULEY
IT之家
IT之家
P
Privacy & Cybersecurity Law Blog
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
D
Docker
Recent Announcements
Recent Announcements
O
OpenAI News
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
Troy Hunt's Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic

Xiaoxia[PG]

Python里使用zbar识别二维码 | Xiaoxia[PG] CentOS7上MySQL返回Too many connections | Xiaoxia[PG] 发现一个不需要打密码的sudo方法 | Xiaoxia[PG] Windows上最小的Python运行环境,700KB | Xiaoxia[PG] 继续玩路由器,交叉编译Python 3.3,压成1.5MB | Xiaoxia[PG] 无聊开始玩路由器,入门Tomato固件 | Xiaoxia[PG] Python与简单网络爬虫的编写 | Xiaoxia[PG] 2012年的中秋节 | Xiaoxia[PG] 悬疑 微电影《生日快乐》/ Once Again | Xiaoxia[PG]
nginx的proxy_pass使用https(SSL加密) | Xiaoxia[PG]
作者是Xiaoxia。 · 2016-07-15 · via Xiaoxia[PG]

写这个文章的原因是因为今晨解决了一个电影FM网友经常访问网站502的问题。最近电影FM粉丝交流群越来越活跃了,感谢Rachel妹纸每周举行的猜电影活动。热衷电影的网友可以加入电影FM的交流QQ群:471644884。最近电影FM的访问量也上升了,高峰时候接近2w一天的IP。今晚美女主持人Kiki来访电影FM时,登录的时候遇到了502,其实我今天访问的时候也出现过一次。为什么会这样呢?

因为电影FM没有网站备案(做电影推荐也需要视听许可证???搞不懂),所以前端流量入口的机器放在阿里云的香港主机,后端也就是网站程序运行的主机在邻近的深圳机房。阿里云的主机之间互相访问速度还是可以的,就是香港主机的线路偶尔也会抽风(比较慢)。当然这些都问题不大,最大问题是香港和深圳的主机之间,多了一道墙。如果我们访问墙外的网站,如果带有敏感词,会被墙挡下来,并且1分钟内都无法访问,不过只是单个人的,还不至于影响所有人。现在问题是墙的工作室双向的,假如有个人在墙外输入了敏感词,墙就会把香港主机和深圳主机的连接挡下来,这时候会让所有用户都上不了网站了。所以为了解决这个问题,要么抛弃墙熟悉的HTTP通信,要么使用HTTPS加密传输(墙绝对不会解密HTTPS)。所以我最后决定在香港和深圳主机之间使用自签名的HTTPS。

回归正题,先生成一个RSA的key,加密算法选择aes也行,des3也行。这里使用1024位的des3。

openssl genrsa -des3 -out ssl.key 1024

会提示必须输入一个密码,随便输入一个就行了,下面我们要解密后才给nginx使用。

openssl rsa -in ssl.key -out fm.key

然后用这个key来生成一个证书请求。

openssl req -new -key fm.key -out fm.csr

接着按照提示,输入证书的信息。

得到csr文件后,通过下面命令生成一个自签名的证书,x509是证书的格式,3650表示证书有效期为10年。

openssl x509 -req days 3650 -in fm.csr -signkey fm.key -out fm.crt

有了fm.crt和fm.key,就可以在nginx上搭建https的服务了。下面是配置https的代码。

server {
listen 443 ssl deferred spdy;
server_name 120.24.x.x;
root /data/fm/www;
ssl on;
ssl_certificate /data/fm/online/certs/fm.crt;
ssl_certificate_key /data/fm/online/certs/fm.key;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 5m;
location / {
proxy_pass http://127.0.0.1:8080/;
}
}

最前端的入口机器在nginx上,proxy_pass的地址把http:// 换成 https:// 。两个nginx都reload一下,