当前位置:   article > 正文

Nginx代理https功能_nginx代理ssl

nginx代理ssl

1.  安装openssl

[root@node2 ~]# yum install -y openssl

2.  生成ssl证书:

  1. [root@node2 ~]# cd /etc/pki
  2. [root@node2 pki]# mkdir nginx
  3. [root@node2 pki]# cd nginx/
  4. ## 生成2048位的加密私钥
  5. [root@node2 nginx]# openssl genrsa -out server.key 2048
  6. ## 生成证书签名请求(CSR),这里需要填写许多信息
  7. [root@node2 nginx]# openssl req -new -key server.key -out server.csr
  8. You are about to be asked to enter information that will be incorporated
  9. into your certificate request.
  10. What you are about to enter is what is called a Distinguished Name or a DN.
  11. There are quite a few fields but you can leave some blank
  12. For some fields there will be a default value,
  13. If you enter '.', the field will be left blank.
  14. -----
  15. Country Name (2 letter code) [XX]:CN ## 国家代号,中国输入CN
  16. State or Province Name (full name) []:SN ## 省的全名,拼音,或者缩写
  17. Locality Name (eg, city) [Default City]:XiAn ## 市的全名,拼音
  18. Organization Name (eg, company) [Default Company Ltd]:openlab ## 公司英文名
  19. Organizational Unit Name (eg, section) []: ## 组织单位名,可以不输入
  20. Common Name (eg, your name or your server's hostname) []:www.openlab.com
  21. ## 服务器主机名,若填写不正确,浏览器会报告证书无效
  22. Email Address []:admin@123.com ## 电子邮箱,可随意填满足格式即可
  23. Please enter the following 'extra' attributes
  24. to be sent with your certificate request
  25. A challenge password []: ## 是否要做密码保护,可以不输入
  26. An optional company name []: ## 可以不输入
  27. ## 查看当前目录是否生成证书
  28. [root@node2 nginx]# ls
  29. server.csr server.key

3.  生成类型为X509的自签名证书,有效期设置3650天。

  1. ## 生成类型为X509的自签名证书。有效期设置3650
  2. [root@node2 nginx]# openssl x509 -req -days 3650 -in server.csr -signkey
  3. server.key -out server.crt
  4. Signature ok
  5. subject=/C=CN/ST=SN/L=XiAn/O=openlab/CN=www.openlab.com/emailAddress=admin@123.com
  6. Getting Private key

 4.  配置Nginx配置文件:

  1. [root@node2 nginx]# vim /etc/nginx/nginx.conf
  2. .......
  3. server {
  4. listen 443 ssl http2;
  5. listen [::]:443 ssl http2;
  6. server_name _;
  7. root /usr/share/nginx/html;
  8. ssl_certificate "/etc/pki/nginx/server.crt"; ## 自签名证书文件,绝对路径
  9. ssl_certificate_key "/etc/pki/nginx/server.key"; ## 加密私钥文件
  10. ssl_session_cache shared:SSL:1m;
  11. ssl_session_timeout 10m;
  12. ssl_ciphers HIGH:!aNULL:!MD5;
  13. ssl_prefer_server_ciphers on;
  14. # Load configuration files for the default server block.
  15. include /etc/nginx/default.d/*.conf;
  16. error_page 404 /404.html;
  17. location = /40x.html {
  18. }
  19. error_page 500 502 503 504 /50x.html;
  20. location = /50x.html {
  21. }
  22. }
  23. .......

5.  配置访问页面:

  1. [root@node2 nginx]# cd /usr/share/nginx/html/
  2. [root@node2 nginx]# mkdir bbs
  3. [root@node2 nginx]# vim bbs/index.html
  4. this bbs pages

6.  访问" https://192.168.188.12/bbs ",查看https是否配置成功:

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号