广告
返回顶部
首页 > 资讯 > 服务器 >nginx结合openssl实现https的方法
  • 639
分享到

nginx结合openssl实现https的方法

2024-04-02 19:04:59 639人浏览 安东尼
摘要

在未使用SSL证书对服务器数据进行加密认证的情况下,用户的数据将会以明文的形式进行传输,这样一来使用抓包工具是可以获取到用户密码信息的,非常危险。而且也无法验证数据一致性和完整性,不

在未使用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

二、创建根证书CA

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

三、根据CA证书创建server端证书

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

四、配置nginx支持SSL


[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内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: nginx结合openssl实现https的方法

本文链接: https://www.lsjlt.com/news/130996.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • nginx结合openssl实现https的方法
    在未使用SSL证书对服务器数据进行加密认证的情况下,用户的数据将会以明文的形式进行传输,这样一来使用抓包工具是可以获取到用户密码信息的,非常危险。而且也无法验证数据一致性和完整性,不...
    99+
    2022-11-12
  • Nginx使用自签ssl证书实现https连接的方法
    目录场景使用OpenSSL创建证书不同格式证书的转换Nginx下ssl配置方法验证方法场景 Nginx使用自签ssl证书实现https连接。 使用OpenSSL创建证书 建立服务器私...
    99+
    2022-11-13
  • nginx与node.js结合使用的方法是什么
    本文小编为大家详细介绍“nginx与node.js结合使用的方法是什么”,内容详细,步骤清晰,细节处理妥当,希望这篇“nginx与node.js结合使用的方法是什么”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。N...
    99+
    2023-07-04
  • 关于Tomcat 结合Atomikos 实现JTA的方法
    最近项目切换环境,把weblogic 换成tomcat 记录中间遇到的问题 Tomcat下配置Atomikos实现JTA Tomcat作为一款经典的Web服务器,在开发、测试和生产环...
    99+
    2022-11-12
  • 在SpringBoot中结合Swagger2实现Restful的方法
    这期内容当中小编将会给大家带来有关在SpringBoot中结合Swagger2实现Restful的方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。pom.xml增加依赖包 <dependency&...
    99+
    2023-05-31
    springboot swagger2 restful
  • Android结合xml实现帧动画的方法
    这篇文章将为大家详细讲解有关Android结合xml实现帧动画的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1 创建 xml 动画文件在 Android 项目工程中的 drawable 目录下创建动...
    99+
    2023-06-15
  • Linux apache实现https的配置方法
    目录http协议:ssl(安全套接层)协议:https协议:http协议:   应用层协议,传输层使用TCP协议,默认使用80端口。http协议主要是用来是实现万维网站点资源的访问。 ssl(安全套接...
    99+
    2022-10-16
  • Linux apache实现https的配置方法
    目录http协议:ssl(安全套接层)协议:https协议:http协议:   应用层协议,传输层使用TCP协议,默认使用80端口。http协议主要是用来是实现万...
    99+
    2022-11-13
    Linux apache配置 Linux apache https配置
  • MyBatis-Plus结合Layui实现分页方法
    MyBatis-Plus 使用简单,内置通用 Mapper、通用 Service,仅仅通过少量配置,即可实现单表大部分 CRUD 操作。下面介绍使用 service 中的 page ...
    99+
    2022-11-12
  • SpringBoot结合Redis实现序列化的方法详解
    目录前言配置类配置 Jackson2JsonRedisSerializer 序列化策略配置  RedisTemplate配置缓存策略测试代码完整代码前言 最近在学...
    99+
    2022-11-13
  • Linux下安装nginx的实现方法
    Nginx 是 C语言 开发,建议在 linux 上运行,当然,也可以安装 Windows 版本, 安装依赖 yum install gcc yum install pcre-devel yum install zl...
    99+
    2022-06-04
    Linux安装nginx
  • SpringBoot结合Mybatis实现创建数据库表的方法
    目录前言为什么要通过应用实现创建表的功能准备创建表的 SQL 语句实现通过 MyBatis 创建数据库表示例在 Maven 中引入相关依赖在 SpringBoot 配置文件中添加数据...
    99+
    2022-11-13
  • .NET Core结合Nacos实现配置加解密的方法
    目录背景简单原理说明自定义 ConfigFilter简单应用写在最后背景 当我们把应用的配置都放到配置中心后,很多人会想到这样一个问题,配置里面有敏感的信息要怎么处理呢? 信息既然敏...
    99+
    2022-11-12
  • springboot整合Nginx实现负载均衡反向代理的方法详解
    目录一、百度百科二、Nginx作为web服务器三、Nginx处理请求逻辑图四、Nginx的优点五、Nginx应用场景1、反向代理2、负载均衡3、动静分离六、Nginx的常用命令1、启...
    99+
    2022-11-12
  • springboot结合mysql主从来实现读写分离的方法
    这篇文章主要介绍springboot结合mysql主从来实现读写分离的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.实现的功能    基于springboot框架,applica...
    99+
    2023-06-14
  • Kotlin结合Rxjava+Retrofit实现极简网络请求的方法
    前言因为最近正在写的项目集成了两个网络请求框架(Volley and Retrofit)对比之下也是选择了Retrofit。既然选择那自然要让自己以后开发更加省力(就是懒)。于是我在Retrofit中加入了Rxjava,这也是当下蛮流行的一...
    99+
    2023-05-30
    retrofit rxjava kotlin
  • shell脚本结合iptables防端口扫描的实现方法
    这篇文章主要讲解了“shell脚本结合iptables防端口扫描的实现方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“shell脚本结合iptables防端口扫描的实现方法”吧!网上有现在...
    99+
    2023-06-09
  • nginx配置防盗链的三种实现方式总结
    目录什么是资源盗链一、引导案例二、Nginx防盗链实现原理三、Nginx防盗链具体实现实现方式一实现方式二实现方式三总结什么是资源盗链 资源盗链是指内容不在自己服务器上,而通过技术手...
    99+
    2022-11-13
  • Django+Nginx+uWSGI定时任务的实现方法
    目录摘要使用uWSGI的cron使用socket.bind锁使用uWSGI的mule摘要 在Nginx和uWSGI还没配置时,单独在url.py使用apscheduler设置定时任务...
    99+
    2022-11-13
  • nginx实现动静分离的方法示例
    目录在server1上部署nginx在server上部署lnmpnode3部署httpd实现分离部署本文主要介绍了nginx实现动静分离的方法示例,具有一定的学习价值,具体如下 环境...
    99+
    2022-11-12
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作