• Nginx1.19.0、Centos7配置Https证书


    本文主要记录基于nginx1.19.0添加对SSL(https)证书的支持的主要操作,方便日后需要。

    约定:

        本次操作目录设定为/opt/soft/nginx/,也作为当前操作的约定目录(cd /opt/soft/nginx/)

        代理机端口:7222,被代理端口:7111

    准备:

      依赖库:yum -y install wget gcc gcc-c++ pcre-devel openssl-devel

      中间件:tomcat,jdk>=1.8

      代理件:nginx >=1.19.0

    一.下载nginx.1.19.0

      下载地址:https://nginx.org/en/download.html

    二.解压tar.gz文件到指定的目录

      tar -xzvf nginx-1.19.0.tar.gz 

    三.默认安装
      cd nginx-1.19.0

      #配置 

      ./configure

      #编译

      make 

      #安装

      make install

      #备份

      cd /usr/local/nginx/sbin 

      cp nginx nginx-default (备份默认安装)

    四.定制模块

      cd /opt/soft/nginx/nginx-1.19.0/

      #配置

      ./configure --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module  

      #编译

      make

      #准备

      cd objs

      #复制

      cp nginx /usr/local/nginx/sbin/ (根据提示输入y允许覆盖)

    五.重启nginx

      systemctl stop nginx.service

      systemctl start nginx.service

    六.证书准备

      准备好您从各证书颁发机构平台申请下来的证书,证书最核心的包含了.pfx,证书密码两部分信息 ;我们暂定证书名字为123456_www.xx.com.pfx 密码为123456

    七.Tomca配置

      7.1jdk.1.8  安装准备

      7.2tomcat  123456_www.xx.com.pfx证书参数配置

      7.3tomcat     123456_www.xx.com.pfx证书配置接入

      7.4Win10   导入123456_www.xx.com.pfx证书

    八.Nginx证书准备

      8.1nginx.conf  修改配置

        http节点内部底部新增配置  include webconf/*.conf;

      8.2新建配置目录

        mkdir webconf

        mkdir ssl_certificate

      8.3上传证书到 ssl_certificate

        上传 123456_www.xx.com.pfx 证书

        a.导出证书

          openssl pkcs12 -in /usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.pfx -out /usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.crt -nodes -nokeys -nokeys

          根据提示输入证书密码

        b.导出私钥

           openssl pkcs12 -in /usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.pfx -out /usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.key -nocerts

        c.公钥不需

    九.https配置

      9.1配置文件

        cd usr/local/nginx/conf/webconf

        vi https_demo.conf 

        保存退出

      9.2站点配置

        upstream https_demo_7222{
            server 192.168.1.140:7111 weight=1; 
        }
    
    
        
        server{
            keepalive_requests 120;
            listen 7222 ssl;
            server_name www.xx.com;
    
            ssl_certificate "/usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.crt";
            ssl_certificate_key "/usr/local/nginx/conf/ssl_certificate/123456_www.xx.com.key";
            ssl_session_cache shared:SSL:1m;
            ssl_session_timeout  10m;
            ssl_ciphers HIGH:!aNULL:!MD5;
            ssl_prefer_server_ciphers on;
    
            charset utf-8;
            client_max_body_size 300M;
            location / 
            {
                    proxy_pass https://https_demo_7222;
                    proxy_set_header REMOTE_ADDR $remote_addr;                
                    proxy_set_header Host $host:$server_port;                
                    proxy_set_header X-Real-IP $remote_addr;                
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header X-Forwarded-Proto https;
            }
        }

        保存配置。

      9.3重启nginx.

        systemctl stop nginx.service

        systemctl strat nginx.service

    10收尾

      至此,基于nginx、tomcat、https证书的配置结束,此时可以通过https://www.xx.com:7222/进行访问了。

        

  • 相关阅读:
    【SQL-自动生成编号】按规则自动生成单据编号 以及并发问题_使用触发器、函数 等
    【C#-枚举】枚举的使用
    问题_VS2008和VS2012未能加载包.....以及破解VS2008方法
    【C#-算法】根据生日自动计算年龄_DataTime 的 DateDiff 方法
    【SQL-分组合并字符串】把相同分组的某个字段合并为同一个字符串(使用函数)
    【Winform-GataGridView】根据DataGridView中的数据内容设置行的文字颜色、背景色 — 根据状态变色
    【Winform-右下角弹窗】实现右下角弹窗,提示信息
    【WinForm-无边框窗体】实现Panel移动窗体,没有边框的窗体
    【Winfrom-适配窗体】 WinForm窗体及其控件的自适应,控件随着窗体变化
    【Winfrom-无边框窗体】Winform如何拖动无边框窗体?
  • 原文地址:https://www.cnblogs.com/oumi/p/14027542.html
Copyright © 2020-2023  润新知