nginxssl证书怎么设置(nginx结合openssl实现https的方法)
类别:服务器 浏览量:2795
时间:2021-10-01 01:19:34 nginxssl证书怎么设置
nginx结合openssl实现https的方法在未使用SSL证书对服务器数据进行加密认证的情况下,用户的数据将会以明文的形式进行传输,这样一来使用抓包工具是可以获取到用户密码信息的,非常危险。而且也无法验证数据一致性和完整性,不能确保数据在传输过程中没被改变。所以网站如果有涉及用户账户等重要信息的情况下通常要配置使用SSL证书,实现https协议。
在生产环境中的SSL证书都需要通过第三方认证机构购买,分为专业版OV证书(浏览器地址栏上不显示企业名称)和高级版EV(可以显示企业名称)证书,证书所保护的域名数不同也会影响价格(比如只对www认证和通配*认证,价格是不一样的),且不支持三级域名。测试中可以自己作为证书颁发机构来制作证书,浏览器会显示为红色,代表证书过期或者无效,如果是黄色的话代表网站有部分连接使用的仍然是http协议。
不管使用哪种方法,在拿到证书后对Nginx的配置都是一样的,所以这里以搭建OpenSSL并制作证书来进行完整说明
一、准备环境1)nginx服务
2)ssl模块
[root@ns3 ~]# systemctl stop firewalld [root@ns3 ~]# iptables -F [root@ns3 ~]# setenforce 0 [root@ns3 ~]# yum -y install pcre zlib pcre-devel zlib-devel [root@ns3 ~]# tar xf nginx-1.16.0.tar.gz -C /usr/src/ [root@ns3 ~]#cd /usr/src/nginx-1.16.0 [root@ns3 ~]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module&&make && make install #后续需要的模块一次性安装
3)检测openssl是否安装
[root@ns3 ~]# rpm -qa openssl 2 openssl-1.0.1e-42.el7.x86_64
若没有安装
[root@ns3 ~]# yum -y install openssl openssl-devel
1、生成CA私钥
[root@ns3 ~]# cd zhengshu/ [root@ns3 zhengshu]# openssl genrsa -out local.key 2048 Generating RSA private key, 2048 bit long modulus ...........................................................................................................................................................................................................................+++ ............................................................................................................................................................................................+++ e is 65537 (0x10001) [root@ns3 zhengshu]# ls local.key
2、生成CA证书请求
[root@ns3 zhengshu]# openssl req -new -key local.key -out local.csr 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]:CN #国家 State or Province Name (full name) []:BJ #省份 Locality Name (eg, city) [Default City]:BJ #城市 Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []:test #部门 Common Name (eg, your name or your server's hostname) []:test #主机名 Email Address []:test@test.com #邮箱 Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:wuminyan #密码 An optional company name []:wuminyan #姓名 [root@ns3 zhengshu]# ls local.csr local.key
req: 这是一个大命令,提供生成证书请求文件,验证证书,和创建根CA -new: 表示新生成一个证书请求 -x509: 直接输出证书 -key: 生成证书请求时用到的私钥文件 -out:输出文件
3、生成CA根证书
这个生成CA证书的命令会让人迷惑 1.通过秘钥 生成证书请求文件 2.通过证书请求文件 生成最终的证书 -in 使用证书请求文件生成证书,-signkey 指定私钥,这是一个还没搞懂的参数 [root@ns3 zhengshu]# openssl x509 -req -in local.csr -extensions v3_ca -signkey local.key -out local.crt Signature ok subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com Getting Private key
1、生成server私匙
[root@ns3 zhengshu]# openssl genrsa -out my_server.key 2048 Generating RSA private key, 2048 bit long modulus .................................+++ .........................................+++ e is 65537 (0x10001) [root@ns3 zhengshu]# ls local.crt local.csr local.key my_server.key
2、生成server证书请求
[root@ns3 zhengshu]# openssl x509 -req -in local.csr -extensions v3_ca -signkey local.key -out local.crt Signature ok subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com Getting Private key [root@ns3 zhengshu]# openssl genrsa -out my_server.key 2048 Generating RSA private key, 2048 bit long modulus .................................+++ .........................................+++ e is 65537 (0x10001) [root@ns3 zhengshu]# openssl req -new -key my_server.key -out my_server.csr 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]:CN State or Province Name (full name) []:BJ Locality Name (eg, city) [Default City]:BJ Organization Name (eg, company) [Default Company Ltd]: Organizational Unit Name (eg, section) []:test Common Name (eg, your name or your server's hostname) []:test Email Address []:test@test.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:wuminyan An optional company name []:wuminyan [root@ns3 zhengshu]# ls local.crt local.csr local.key my_server.csr my_server.key
3、生成server证书
[root@ns3 zhengshu]# openssl x509 -days 365 -req -in my_server.csr -extensions v3_req -CAkey local.key -CA local.crt -CAcreateserial -out my_server.crt Signature ok subject=/C=CN/ST=BJ/L=BJ/O=Default Company Ltd/OU=test/CN=test/emailAddress=test@test.com Getting CA Private Key
[root@ns3 ~]# vim /etc/nginx.cof #这里设置了一个软连接:lln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ server { listen 80; listen 443 default ssl; #监听433端口 keepalive_timeout 100; #开启keepalive 激活keepalive长连接,减少客户端请求次数 ssl_certificate /root/zhengshu/local.crt; #server端证书位置 ssl_certificate_key /root/zhengshu/local.key; #server端私钥位置 ssl_session_cache shared:SSL:10m; #缓存session会话 ssl_session_timeout 10m; # session会话 10分钟过期 ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; server_name test.com; charset utf-8; location / { root html; index index.html index.htm; } } }
输入https://192.168.200.115
到此这篇关于nginx结合openssl实现https的文章就介绍到这了,更多相关nginx实现https内容请搜索开心学习网以前的文章或继续浏览下面的相关文章希望大家以后多多支持开心学习网!
您可能感兴趣
- centos7 离线安装nginx(centos8安装nginx1.9.1的详细过程)
- nginx是怎样负载均衡的(Nginx四层负载均衡的配置指南)
- linuxnginx常用状态命令(nginx常用命令放入shell脚本详解)
- nginx文件夹限制ip访问(基于Nginx实现限制某IP短时间访问次数)
- nginxtomcat工作原理(Windwos下实现Nginx+Tomcat集群过程解析)
- nginxlocation和alias的区别(nginx搭建图片服务器的过程详解root和alias的区别)
- nginx为什么要配置https(Nginx配置Https安全认证的实现)
- nginx查看rewrite日志(Nginx Rewrite使用场景及配置方法解析)
- nginx故障处理(详解Nginx启动失败的几种错误处理)
- nginx负载均衡高怎么用(Nginx + consul + upsync 完成动态负载均衡的方法详解)
- nginx代理转发域名(Nginx域名转发使用场景代码实例)
- nginx负载均衡器的作用(Nginx 负载均衡是什么以及该如何配置)
- nginx负载均衡5种方法(Nginx如何配置负载均衡)
- docker重新加载nginx(Docker Nginx Log 三者的处理详解)
- docker nginx 配置详解(Docker 如何安装 Nginx)
- nginx-rtmp-module 配置(Nginx搭建rtmp直播服务器实现代码)
- 经常发这三种 朋友圈 的人,要迅速屏蔽(经常发这三种朋友圈)
- 有种尴尬叫朋友圈忘屏蔽,大学生上演社死现场,父母亲自下场吐槽(有种尴尬叫朋友圈忘屏蔽)
- 朋友圈屏蔽你的人,可以直接看淡了(朋友圈屏蔽你的人)
- 金球奖只青睐那些会戴珠宝的女人(金球奖只青睐那些会戴珠宝的女人)
- 浙江省一个县,人口超40万,建县历史超1100年(浙江省一个县人口超40万)
- 五代十国南唐历代国君(五代十国南唐历代国君)
热门推荐
- python中的多线程详解(python多线程抽象编程模型详解)
- 前端轮播图效果(AmazeUI图片轮播效果的示例代码)
- Sql Server常用系统存储过程
- Visual Studio使用Git进行源代码管理
- laravel 数据库配置信息(Laravel 读取 config 下的数据方法)
- VPS服务器常用性能测试脚本汇总(VPS服务器常用性能测试脚本汇总)
- sql注入测试常用的工具(Sql注入工具_动力节点Java学院整理)
- python中如何清空列表数据(Python批量删除只保留最近几天table的代码实例)
- python提取字符串中的正则表达式(python3正则提取字符串里的中文实例)
- python如何读取文件(Python从文件中读取数据的方法讲解)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9