nginx开启ssl配置https证书和密钥过程
2021-04-07 11:27
标签:测试 系统 输入密码 gen ati 网络服务 获取 address 双向 配置完成访问浏览器后,网站前面会出现红色的叉,这是因为在网络服务器上找不到对应的证书厂商,不妨碍使用。 这里以nginx1.16.1为例 [root@~]curl -O http://nginx.org/download/nginx-1.16.1.tar.gz [root@~] tar -zxvf nginx-1.16.1.tar.gz [root@~] cd nginx-1.16.1 [root@ nginx-1.16.1]make [root@~]cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak [root@~]/usr/local/nginx/sbin/nginx -V [root@~]openssl genrsa -des3 -out server.key 1024 kpy@hw Country Name (2 letter code) [XX]:CN # 国家缩写 [root@~]cp server.key server.key.org [root@~]openssl x509 -req -days 180 -in server.csr -signkey server.key -out server.crt http://nginx.org/en/docs/http/configuring_https_servers.html#single_http_https_server nginx开启ssl配置https证书和密钥过程 标签:测试 系统 输入密码 gen ati 网络服务 获取 address 双向 原文地址:https://blog.51cto.com/14483703/2477954
本教程是在Centos7上配置,其他版本的linux改一下对应的命令即可。供参考
Nginx 开启SSL 配置证书和私钥,需要安装openssl
获取安装包
或者 wget http://nginx.org/download/nginx-1.16.1.tar.gz解压
编译模块
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-https_ssl_module如果之前已经安装nginx的,这里就不再make install,否则会覆盖掉之前的安装和配置
备份原先的启动文件
查看模块是否加载
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module # 模块已加载加载ssl模块后,会在nginx.conf加上配置文件HTTPS SERVER 后面的ssl信息,
注意:一般生成的目录,应该放在nginx/conf/ssl目录,可以自定义
生成证书和密钥 -des3: CBC模式的DES加密 以下示例生成一个1024位的RSA私钥
输入密码,2次
Generating RSA private key, 1024 bit long modulus
....++++++
.......................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:创建服务器证书的申请文件 server.csr
[root@~]openssl req -new -key server.key -out server.csr
Enter pass phrase for 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.填写下面的信息
State or Province Name (full name) []:GuangDong #省份
Locality Name (eg, city) [Default City]:GuangZhou # 市
Organization Name (eg, company) [Default Company Ltd]:lw666.cn # 公司名
Organizational Unit Name (eg, section) []: # 组织名,可以不填
Common Name (eg, your name or your server‘s hostname) []: #公共名,可以不填
Email Address []:123456@lw666.cn # 邮箱地址,可以不填
Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []: # 加强的密码,可以不填
An optional company name []: # 可以不填备份文件,跳过证书验证密码,生成server.crt文件
[root@~]openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org: # 输入上面的密码
writing RSA key生成证书, 证书有效天数(如果输入9999表示永久) 签名,开启双向认证
Signature oksubject=/C=CN/ST=GuangDong/L=GuangZhou/O=lwops.cn/emailAddress=123456@lw666.cn
br/>subject=/C=CN/ST=GuangDong/L=GuangZhou/O=lwops.cn/emailAddress=123456@lw666.cn
Getting Private keyvi nginx.conf,注释掉HTTPS SERVER,单个server,直接把listen到最后一行ssl替换原来的listen 80,然后测试配置文件
参考官方配置资料:
单个server可以80和433共存,但80的还是http
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
# ssl on; nginx1.15版本之前需要加,之后的不用加
# 证书路径和密钥路径
文章标题:nginx开启ssl配置https证书和密钥过程
文章链接:http://soscw.com/index.php/essay/72372.html