Nginx下openssl颁发SSL证书

  1. Nginxopenssl颁发SSL证书
  2.  
  3. 1) rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  4. 2) yum install nginx php-fpm.x86_64 -y
  5. 3) cd /etc/nginx/conf.d
  6. 4) openssl genrsa -des3 -out baiqiuyi.com.key 2048 #创建私钥 (没密码 openssl genrsa -out baiqiuyi.com.key 2048)
  7. 5) openssl req -new -key baiqiuyi.com.key -out baiqiuyi.com.csr #证书签名
  8. 6) openssl x509 -req -days 365 -in baiqiuyi.com.csr -signkey baiqiuyi.com.key -out baiqiuyi.com.crt #用私钥及证书签名颁发证书
  9. 7) #添加至nginx配置文件
  10. ssl on;
  11. ssl_certificate /etc/nginx/conf.d/baiqiuyi.com.crt;
  12. ssl_certificate_key /etc/nginx/conf.d/baiqiuyi.com.key;
  13. 8) openssl rsa -in baiqiuyi.com.key  -out nopasswd.baiqiuyi.com.key #移除密码,如果不希望Nginx重启需要输入密码则使用这个key
  14. #nginx配置文件
  15. server {
  16.     listen       80;
  17.     listen       443;
  18. #
  19. ssl on;
  20. ssl_certificate /etc/nginx/conf.d/baiqiuyi.com.crt;
  21. #ssl_certificate_key /etc/nginx/conf.d/baiqiuyi.com.key;
  22. ssl_certificate_key /etc/nginx/conf.d/nopasswd.baiqiuyi.com.key;
  23.     server_name  localhost;
  24.     location / {
  25.         root   /usr/share/nginx/html;
  26.         index  index.php index.html index.htm;
  27.     }
  28.     location ~ \.php$ {
  29.         root          /usr/share/nginx/html;
  30.         fastcgi_pass   127.0.0.1:9000;
  31.         fastcgi_index  index.php;
  32.         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  33.         include        fastcgi_params;
  34.     }
  35. }
1 1