免费ssl证书:网站域名使用 https (nginx) 访问配置参考
发布时间:2016-01-21, 15:12:19 分类:Linux | 编辑 off 网址 | 辅助
图集1/13
正文 1404字数 1,018,405阅读
采用 SSL 证书加密访问的 https 网站,在一定程度上加密了数据传输,可以避免传输过程中的隐私数据泄露。谷歌在 2014 年宣布对于带有 SSL 证书的网站给予更高的权重。最近百度也明确指出全面支持https页面直接收录,并且采用https协议的页面更加安全,排名上会优先对待。
【官方建议】百度spider工程师给https站点的技术建议
http://zhanzhang.baidu.com/college/articleinfo?id=489
Run code
Cut to clipboard
这里我们要探讨的是nginx 服务器下网站改用 https 的方法。
1. 申请免费的 ssl 证书
你可以参考如下的地址申请免费的 ssl 证书,也可以依据网站安全级别需要,购买付费的级别更高的 SSL 证书服务。
有如下几个提供免费 ssl 证书的地方,请自行选择其一,注册账号,按照提示逐步注册免费 ssl 证书。
一般十分钟左右即可搞定。
http://freessl.wosign.com/freessl
http://www.zzidc.com/main/ssl/showmianfei.html
https://www.startssl.com/
Run code
Cut to clipboard
取得 ssl 证书下载下来,解压后的文件图一所示。这里解压 for nginx 的 zip 包,得到一个 key 和 crt 文件。
2. 上传 SSL 证书
上传证书文件到服务器任意目录,如上传到 /root/ssl/ 目录下。
然后解密私钥和设置权限:
openssl rsa -in /root/ssl/2_lzw.me.key -out /root/ssl/2_lzw.me.key
chmod 600 /root/ssl/2_lzw.me.key
Run code
Cut to clipboard
3. 修改配置 nginx
修改网站站点的 nginx 配置文件,如: vi /usr/local/nginx/conf/vhost/domain.conf。
我们这里会增加 https 的访问,并针对 http 访问做 301 重定向。修改后的设置参考如下:
# http 301 to https
server {
listen 80;
server_name lzw.me www.lzw.me;
return 301 https://$server_name$request_uri;
}
server {
#listen 80;
#listen [::]:80;
listen 443 ssl;
ssl on;
ssl_certificate /root/ssl/1_lzw.me_bundle.crt;
ssl_certificate_key /root/2_lzw.me.key;
server_name lzw.me www.lzw.me;
....
Run code
Cut to clipboard
修改完成后,重启 nginx,即可生效。
原文 https://lzw.me/a/free-ssl-https-nginx.html
Run code
Cut to clipboard
(支付宝)给作者钱财以资鼓励 (微信)→
有过 3 条评论 »
NGINX BIO_new_file
2016/03/21 16:57:10 [emerg] 30420#29876: BIO_new_file("C: ginx-1.9.9\ssl\1_domain_bundle.crt") failed (SSL: error:0200107B:system library:fopen:Unknown error:fopen('C: ginx-1.9.9\ssl\1_domain_bundle.crt','r') error:2006D002:BIO routines:BIO_new_file:system lib) 2016/03/21 16:57:11 [alert] 29884#31740: worker process 30420 exited with code 1 2016/03/21 16:57:11 [alert] 29884#31740: could not respawn worker 2016/03/21 16:57:28 [emerg] 28212#30316: BIO_new_file("C: ginx-1.9.9\ssl\1_domain_bundle.crt") failed (SSL: error:0200107B:system library:fopen:Unknown error:fopen('C: ginx-1.9.9\ssl\1_domain_bundle.crt','r') error:2006D002:BIO routines:BIO_new_file:system lib)
问题分析:只要写绝对路径,就会报错,无论windows还是linux,怀疑是对路径的处理有问题
解决办法
windows下,将证书文件放到conf目录下,
linux下,将证书文件放到nginx.conf所在的目录下
检测端口是否开启
netstat -ano -p tcp | find "443" >nul 2>nul && echo 443端口已开启 || echo 443未开启
另一个程序正在使用此文件,进程无法访问。 (异常来自 HRESULT:0x80070020)
[SVN] VisualSVN Server Manager 443端口
netstat -aon|findstr "443"
得到占用443端口的进程ID,发现是VisualSVNServer.exe占用了它。
修改VisualSVN Server Manager的端口方法如下:
(1)打开VisualSVN Server Manager
(2)点击根节点“VisualSVN Server Manager (Local)”
(3)右键-Properties
(4)Network选项卡,Server Port选为8443
证书系统创建的CSR,包含:证书私钥文件214405557430106.key、PFX格式证书文件214405557430106.pfx、PFX格式证书密码文件pfx-password.txt
IIS7/IIS7.5 URL 重写 HTTP 重定向到 HTTPS
进入“URL重写”模块,点击“添加规则”
选择“空白规则”
名称:HTTP to HTTPS redirect 模式:(.*)
条件输入:{HTTPS} 模式:off 或 ^OFF$
或
重定向URL:https://{HTTP_HOST}/{R:1} 重定向类型:已找到(302) 或 参阅其它(303)
或
配置完成后“应用”到当前站点
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Client] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Server] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Client] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Server] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client] "DisabledByDefault"=dword:00000001 "Enabled"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server] "Enabled"=dword:00000000 "DisabledByDefault"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server] "Enabled"=dword:00000001 "DisabledByDefault"=dword:00000000
双击执行,重启服务器 TLS1.2.reg