下载服务器证书压缩包 php
解压后应包含两个文件:linux
yourdomain.com.crt (服务器证书) yourdomain.com.key (私钥文件)若是为空请将生成CSR时保存的私钥内容粘贴在文件中nginx
环境检测,检测命令以下(测试nginx是否支持SSL)web
nginx -Vcentos
若是有输入 –with-http_ssl_module 表示已编译openssl,支持安装ssl安全
若是没有安装请下载nginx源码从新编译服务器
./configure --with-http_stub_status_module --with-http_ssl_module make && make installdom
配置Nginxtcp
server { listen 80; listen 443 ssl; server_name www.gworg.cn; ssl_protocols TLSv1.2 TLSv1.1 TLSv1; ssl_certificate /etc/ssl/yourdomain.com.crt; ssl_certificate_key /etc/ssl/yourdomain.com.key; ssl_prefer_server_ciphers on; #自动跳转到HTTPS (可选) if ($server\_port = 80) { rewrite ^(.\*)$ https://$host$1 permanent; } location / { root /home/web/; index index.php; } }测试
以上配置仅供参考,其余参数请根据生产环境须要添加。
安装后重启nginx使其生效
centos6 service nginx restart centos7 systemctl restart nginx
问题排查:
若是使用CDN(加速器),须要在CDN上面安装证书,国内免费加速的都不支持https(已知阿里云cdn支持)
检查443端口是否启动 使用下面命令 netstat -apnt | grep 443 (若是没有启动检查配置文件或者端口是否冲突)
443端口若是已经启动,但不能访问,请检查防火墙(或者安全狗) ,容许443端口.
linux iptables使用下面命令:
iptables -A INPUT -p tcp -m tcp --dport https -j ACCEPT