Nginx安装SSL证书 Nginx配置https证书

Nginx安装SSL证书 Nginx配置https证书

首先拿到Nginx服务器证书
  1. yourdomain.com.crt     (服务器证书)
  2. yourdomain.com.key   (私钥文件)如果为空请将生成CSR时保存的私钥内容粘贴在文件中

环境检测,检测命令如下(测试nginx是否支持SSL)
  1. nginx -V

如果有显示 –with-http_ssl_module 表示已编译openssl,支持安装ssl
如果没有安装请下载nginx源码重新编译
  1. ./configure --with-http_stub_status_module --with-http_ssl_module
  2. make && make install
配置Nginx
  1. server {
  2. listen 80;
  3. listen 443 ssl;
  4. server_name www.yourdomain.cn;
  5. ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
  6. ssl_certificate /etc/ssl/yourdomain.com.crt;
  7. ssl_certificate_key /etc/ssl/yourdomain.com.key;
  8. ssl_prefer_server_ciphers on; 
  9. #自动跳转到HTTPS (可选)
  10. if ($server_port = 80) {
  11. rewrite ^(.*)$ https://$host$1 permanent;}
  12. location / {
  13. root /home/getssl/;
  14. index index.php;
  15. }
  16. }
以上配置仅供参考,其他参数请根据生产环境需要添加。
安装后重启nginx使其生效
  1. centos6
  2. service nginx restart
  3. centos7
  4. systemctl restart nginx
川公网安备 51019002001185号