1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| [root@web01 ~] [root@web01 nginx] [root@web01 nginx]
[root@web01 ssl_key] Generating RSA private key, 2048 bit long modulus ..............+++ ..................................+++
e is 65537 (0x10001) Enter pass phrase for server.key: 123456 Verifying - Enter pass phrase for server.key: 123456 [root@web01 ssl_key] total 4 -rw-r--r--. 1 root root 1739 Dec 9 11:27 server.key
[root@web01 ssl_key] Generating a 2048 bit RSA private key .....................................+++ ............+++ writing new private key to 'server.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:china string is too long, it needs to be less than 2 bytes long Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:meiguo Locality Name (eg, city) [Default City]:riben Organization Name (eg, company) [Default Company Ltd]:heishoudang Organizational Unit Name (eg, section) []:oldboy Common Name (eg, your name or your server's hostname) []:oldboy Email Address []:123@qq.com # req --> 用于创建新的证书 # new --> 表示创建的是新证书 # x509 --> 表示定义证书的格式为标准格式 # key --> 表示调用的私钥文件信息 # out --> 表示输出证书文件信息 # days --> 表示证书的有效期 # sha256 --> 加密方式
#1.开启证书 Syntax: ssl on | off; Default: ssl off; Context: http, server #2.指定证书文件 Syntax: ssl_certificate file; Default: — Context: http, server #3.指定私钥文件 Syntax: ssl_certificate_key file; Default: — Context: http, server
#4.修改nginx配置文件(如果负载均衡配置了就不需要下面的配置了) [root@web01 ~]# cat /etc/nginx/conf.d/https.conf server { listen 443 ssl; server_name _;
ssl_certificate /etc/nginx/ssl_key/server.crt; ssl_certificate_key /etc/nginx/ssl_key/server.key;
location / { root /opt/code; index index.html; } }
#5.重启nignx服务 [root@lb01 ~]# systemctl restart nginx
#6.测试 浏览器访问:https://192.168.15.8/
|