编译配置nginx支持国密(二)

从官网下载nginx源码 http://nginx.org/en/download.html,我下载的是1.18版本

  1. 下载解压到root目录下

  2. 进入目录 cd /root/nginx-1.18.0

  3. 编辑auto/lib/openssl/conf,将全部 $OPENSSL/.openssl/修改为$OPENSSL/并保存

  4. 编译配置

    ./configure \
    --without-http_gzip_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_v2_module \
    --with-file-aio \
    --with-openssl="/usr/local/gmssl" \
    --with-cc-opt="-I/usr/local/gmssl/include" \
    --with-ld-opt="-lm"
    
  5. 编译安装
    make install

  6. /usr/local/nginx即为生成的nginx目录

注:可能需要使用yum install pcre-devel需要安装pcre-devel

  1. 单向https配置

    server
    {
      listen 0.0.0.0:443 ssl;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:AES128-SHA:DES-CBC3-SHA:ECC-SM4-SM3:ECDHE-SM4-SM3:SM2-WITH-SMS4-SM3:ECDHE-SM2-WITH-SMS4-GCM-SM3;
      ssl_verify_client off;
    
      ssl_certificate /usr/local/nginx/conf/demo1.sm2.sig.crt.pem;
      ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.sig.key.pem;
    
      ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.enc.key.pem;
      ssl_certificate /usr/local/nginx/conf/demo1.sm2.enc.crt.pem;
    
      location /
      {
        root html;
        index index.html index.htm;
      }
    }
    

    注意:

    SM2-WITH-SMS4-SM3: 这一个cipher是360浏览器访问时用到的

    ECDHE-SM2-WITH-SMS4-GCM-SM3: 这个cipher是在使用gmssl s_client 命令时用到的

    其他的有些是RSA用到的,可以不配置,这个随意。

    配置完以上的后,重启nginx

    • 使用 gmssl s_client -tls1_2 -connect localhost:443 -cipher SM2 -CAfile demo1.sm2.trust.pem 可以正常链接。
      - 注意:如果你在nginx上部署了应用,使用s_client连接后是没有直接访问到应用的,下一步发送数据 “GET /” ,才能访问到,比如登录页面。
    • 使用360安全浏览器访问 https://ip 也能正常打开欢迎页面。(ip是你部署nginx的电脑,360安全浏览器是在windows系统中使用的)
  2. 双向https配置

    server
    {
      listen 0.0.0.0:443 ssl;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:AES128-SHA:DES-CBC3-SHA:ECC-SM4-SM3:ECDHE-SM4-SM3:SM2-WITH-SMS4-SM3:ECDHE-SM2-WITH-SMS4-GCM-SM3;
      ssl_client_certificate /usr/local/nginx/conf/demo1.sm2.trust;
      ssl_verify_client on;
    
      ssl_certificate /usr/local/nginx/conf/demo1.sm2.sig.crt.pem;
      ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.sig.key.pem;
    
      ssl_certificate /usr/local/nginx/conf/demo1.sm2.enc.crt.pem;
      ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.enc.key.pem;
    
      location /
      {
        root html;
        index index.html index.htm;
      }
    }
    

    双向的测试也可以使用 gmssl s_client的命令。

    使用360测试双向的暂时还没找到方法,暂且放置。

  3. 单向 RSA/国密自适应

server
{
  listen 0.0.0.0:443 ssl;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:AES128-SHA:DES-CBC3-SHA:ECC-SM4-SM3:ECDHE-SM4-SM3:SM2-WITH-SMS4-SM3:ECDHE-SM2-WITH-SMS4-GCM-SM3;
  ssl_verify_client off;

  ssl_certificate /usr/local/nginx/conf/demo1.rsa.crt.pem;
  ssl_certificate_key /usr/local/nginx/conf/demo1.rsa.key.pem;

  ssl_certificate /usr/local/nginx/conf/demo1.sm2.sig.crt.pem;
  ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.sig.key.pem;

  ssl_certificate /usr/local/nginx/conf/demo1.sm2.enc.crt.pem;
  ssl_certificate_key /usr/local/nginx/conf/demo1.sm2.enc.key.pem;

  location /
  {
    root html;
    index index.html index.htm;
  }
}

以上配置完后,使用IE浏览器和360安全浏览器访问 https://ip 都是可以打开欢迎页面的。

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值