nginx 配置https并自签名证书
作者: daodaoliang
版本: V1.0.1
邮箱: daodaoliang@yeah.net
1. 制作服务器证书
服务器CA私钥:
openssl genrsa -des3 -out ca.key 2048
制作解密后的CA私钥(一般无此必要):
openssl rsa -in ca.key -out ca_decrypted.key
ca.crt CA根证书(公钥):
openssl req -new -x509 -days 7305 -key ca.key -out ca.crt
2. 制作生成网站的证书并用CA签名认证
在这里,假设网站域名为 www.example.com
生成 www.example.com 证书私钥:
openssl genrsa -des3 -out www.example.com.pem 1024
制作解密后的 www.example.com 证书私钥:
openssl rsa -in www.example.com.pem -out www.example.com.key
生成签名请求:
openssl req -new -key www.example.com.pem -out www.example.com.csr
在common name中填入网站域名,如 www.example.com 即可生成改站点的证书,同时也可以使用泛域名如 *.example.com 来生成所有二级域名可用的网站证书。
用CA进行签名:
openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in www.example.com.csr -out www.example.com.crt
其中,policy参数允许签名的CA和网站证书可以有不同的国家、地名等信息,days参数则是签名时限。
如果在执行签名命令时,出现“I am unable to access the ../../CA/newcerts directory”
修改/etc/pki/tls/openssl.cnf中“dir = ./CA”
然后:
mkdir -p CA/newcerts
touch CA/index.txt
touch CA/serial
echo "01" > CA/serial
再重新执行签名命令。
最后,把ca.crt的内容粘贴到 www.example.com.crt 后面。这个比较重要!因为不这样做,可能会有某些浏览器不支持。
好了,现在https需要到的网站私钥 www.example.com.key 和网站证书 www.example.com.crt 都准备完毕。接下来开始配置服务端。
3. 配置nginx
新开一个虚拟主机,并在server{}段中设置:
listen 443;
ssl on;
ssl_certificate /path/to/www.example.com.crt;
ssl_certificate_key /path/to/www.example.com.key;
其中的路径是刚刚生成的网站证书的路径。
然后使用一下命令检测配置和重新加载nginx:
检测配置:
nginx -t
重新加载:
nginx -s reload
4. 优化nginx配置
https和http共存:
server {
listen 80;
listen 443 ssl;
server_name zou.lu;
root /var/www/html;
#ssl on; //这行必须要注释掉
ssl_certificate /usr/local/nginx/conf/zou_lu.crt;
ssl_certificate_key /usr/local/nginx/conf/zoulukey.pem;
}
优化性能:
在http{}中加入:
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
据官方文档所述,cache中的1m可以存放4000个session。
在配置https的虚拟主机server{}中加入:
keepalive_timeout 70;
PS:常见错误:
| 有时候,会发现,在phpMyAdmin等程序登入后会错误地跳转http的问题。解决方法是定位至“location ~ .*.(php | php5)?${}”在include fcgi.conf;或者在fastcgi_param配置后面加上: |
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
http://daodaoliang.com/blog/2016/10/28/nginx%E9%85%8D%E7%BD%AEhttps%E5%B9%B6%E8%87%AA%E7%AD%BE%E5%90%8D%E8%AF%81%E4%B9%A6.html
nginx 配置https并自签名证书的更多相关文章
- 为nginx配置https并自签名证书
一.把证书准备好. 步骤与使用OpenSSL自签发服务器https证书所述大同小异.在这里再重复一次. 1.制作CA证书: ca.key CA私钥: openssl genrsa -des3 -out ...
- nginx配置https转发到tomcat(使用自签名的证书)
一.使用openSSL生成自签名的证书 1.生成RSA私钥 命令:openssl genrsa -des3 -out server.key 1024 说明:生成rsa私钥,des3算法,1024强度, ...
- nginx配置https及Android客户端访问自签名证书
前一篇随笔通过keytool生成keystore并为tomcat配置https,这篇随笔记录如何给nginx配置https.如果nginx已配置https,则tomcat就不需要再配置https了.通 ...
- nginx配置https双向验证(ca机构证书+自签证书)
nginx配置https双向验证 服务端验证(ca机构证书) 客户端验证(服务器自签证书) 本文用的阿里云签发的免费证书实验,下载nginx安装ssl,文件夹有两个文件 这两个文件用于做服务器http ...
- 购买https证书以及nginx配置https
文章来源 运维公会:购买https证书以及nginx配置https 1.https的作用 https的全名是安全超文本传输协议,是在http的基础上增加了ssl加密协议.在信息传输的过程中,信息有可能 ...
- 【Nginx(五)】Nginx配置Https证书
大致的流程如下 1.申请Https证书,绑定域名信息; 由于自己的服务器是腾讯云服务器, 这里就在腾讯云上申请SSL证书, 申请地址: https://console.cloud.tencent.co ...
- 【转】Linux下nginx配置https协议访问的方法
一.配置nginx支持https协议访问,需要在编译安装nginx的时候添加相应的模块--with-http_ssl_module 查看nginx编译参数:/usr/local/nginx/sbin/ ...
- lnmp之Nginx配置https加密访问
配置lnmp之Nginx网站支持https加密访问 注: 1. 这里拿购买的(pxsnx.pxjy.com)证书来做样例 证书文件共有三个---> (pxsnxg.pxjy.com_ca.crt ...
- Nginx 配置https 服务
一.HTTPS 服务 为什么需要HTTPS? 原因:HTTP不安全 1.传输数据被中间人盗用.信息泄露 2.数据内容劫持.篡改 HTTPS协议的实现 对传输内容进行加密以及身份验证 HTTPS加密校验 ...
随机推荐
- Windows应用程序的消息处理机制
(1)操作系统接收到应用程序的窗体消息,将消息投递到该应用程序的消息队列中. (2)应用程序在消息循环中调用GetMessage函数从消息队列中取出一条一条的消息. 取出消息后,应用程序能够对消息进行 ...
- Android Studio 使用教程(二十五)之运行Android Studio工程
一.Android虚拟设备入口 上期我们使用了Android Studio创建了HeloWorld工程,要想运行该工程,首先需要一个Android虚拟设备来模拟Android程序的运行. 重新打开An ...
- ashx 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
1.点击查看ashx在浏览器中显示的信息 2.自定义协议头 这样问题就搞定了.当然只是我遇到的一种.
- LVS实现负载均衡原理及安装配置
LVS实现负载均衡原理及安装配置 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F ...
- 一组西门子S7 报文
03 00 00 16 11 E0 00 00 00 01 00 C1 02 10 00 C2 02 03 01 C0 01 0A(第一次握手报文) 03 00 00 16 11 D0 00 01 0 ...
- 理解 t-SNE (Python)
t-SNE(t-distribution Stochastic Neighbor Embedding)是目前最为流行的高维数据的降维算法. t-SNE 成立的前提基于这样的一个假设:我们现实世界观察到 ...
- 深入python3 (Dive Into Python 3) 在线阅读与下载
在线阅读:http://book.doucube.com/diveintopython3/ 中文版 下载地址:https://github.com/downloads/diveintomark/di ...
- c#-WPF string,color,brush之间的转换
原文:c#-WPF string,color,brush之间的转换 String转换成Color string-"ffffff" Color color = (Color)Colo ...
- Linux 下编译并安装配置 Qt 4.53全过程
最近准备做 Nokia 的 Symbian,Maemo 下触摸屏开发.考虑到程序的跨平台可移植性,最终选择使用 Qt 开发.相对来说,国内关于 Qt 相关文档并不算很多.作者将 Linux 下编译并安 ...
- CF 455A(Boredom-dp)
A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input out ...