使用Docker编译OpenResty支持国密ssl加密

本文涉及的产品
密钥管理服务KMS,1000个密钥,100个凭据,1个月
简介: OpenResty自身支持标准SSL协议,但不支持国密SSL协议;本文主要概述如何在docker环境下编译OpenResty镜像支持国密SSL加密。

编译环境

执行编译操作环境如下

#操作系统
CentOS Linux release 7.4.1708 (Core)
#docker版本
 Version:           19.03.5

编译过程

Dockerfile如下

FROM centos:7

WORKDIR  /usr/local/gm-openresty
# 安装所需依赖包
RUN yum -y install perl make gcc gcc-c++ libstdc++-devel pcre-devel zlib-devel net-tools pcre wget && \
yum clean all && \
wget https://www.gmssl.cn/gmssl/Tool_Down?File=gmssl_openssl_1.1_b4.tar.gz && tar xzfm Tool_Down?File=gmssl_openssl_1.1_b4.tar.gz -C /usr/local && \
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz && tar xzfm openresty-1.19.3.1.tar.gz && \
ln -s /usr/lib64/libpcre.so.1 /usr/lib64/libpcre.so.3

RUN sed -i 's#$OPENSSL/.openssl/#$OPENSSL/#p' /usr/local/gm-openresty/openresty-1.19.3.1/bundle/nginx-1.19.3/auto/lib/openssl/conf && \
cd openresty-1.19.3.1/ && \
./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" && \
make install && \
rm -rf /usr/local/gm-openresty/* && \
ln -sf /dev/stdout /usr/local/openresty/nginx/logs/access.log && \
ln -sf /dev/stderr /usr/local/openresty/nginx/logs/error.log

# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin

EXPOSE 80 443
CMD ["/usr/bin/openresty", "-g", "daemon off;"]

# Use SIGQUIT instead of default SIGTERM to cleanly drain requests
# See https://github.com/openresty/docker-openresty/blob/master/README.md#tips--pitfalls
STOPSIGNAL SIGQUIT
  • 构建镜像
docker build -t openresty-gm:v1 .
  • 启动
$ docker run -it -p 80:80 -p 443:443  -v /root/openresty/cert:/usr/local/cert -v /root/openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf  openresty-gm:v1 bash

#在容器中执行openresty命令即可启动
$ openresty

nginx.conf 内容

worker_processes  2;
events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;


    sendfile        on;
    keepalive_timeout  65;

   server
    {
      listen 0.0.0.0:80;
      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-CBC-SM3:ECDHE-SM4-GCM-SM3;
      ssl_verify_client off;

      ssl_certificate /usr/local/cert/test.cn_RSA.crt;
      ssl_certificate_key /usr/local/cert/test.cn_RSA.key;

      ssl_certificate /usr/local/cert/test.cn_sm2_sign.crt;
      ssl_certificate_key /usr/local/cert/test.cn_SM2.key;

      ssl_certificate /usr/local/cert/test.cn_sm2_encrypt.crt;
      ssl_certificate_key /usr/local/cert/test.gov.cn_SM2.key;

      location /
      {
        root html;
        index index.html index.htm;
      }
   }
}
  • 客户端使用360安全浏览器访问

参考文章

相关文章
|
12天前
|
应用服务中间件 nginx Docker
Docker镜像-基于DockerFile制作编译版nginx镜像
这篇文章介绍了如何基于Dockerfile制作一个编译版的nginx镜像,并提供了详细的步骤和命令。
89 17
Docker镜像-基于DockerFile制作编译版nginx镜像
|
4月前
|
NoSQL 测试技术 Go
【Golang】国密SM2公钥私钥序列化到redis中并加密解密实战_sm2反编(1)
【Golang】国密SM2公钥私钥序列化到redis中并加密解密实战_sm2反编(1)
|
17天前
|
Android开发 Docker 容器
docker中编译android aosp源码,出现Build sandboxing disabled due to nsjail error
在使用Docker编译Android AOSP源码时,如果遇到"Build sandboxing disabled due to nsjail error"的错误,可以通过在docker run命令中添加`--privileged`参数来解决权限不足的问题。
51 1
|
1月前
|
jenkins 网络安全 持续交付
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
24 0
|
1月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
140 0
|
1月前
|
Android开发
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
132 0
|
3月前
|
敏捷开发 API 持续交付
阿里云云效产品使用问题之流水线编译docker时,如何把已经定义好的token传入编译参数
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
阿里云云效产品使用问题之流水线编译docker时,如何把已经定义好的token传入编译参数
|
2月前
|
安全 网络协议 网络安全
SSL(Secure Sockets Layer)是一种安全协议,用于在客户端和服务器之间建立加密的通信通道。
SSL(Secure Sockets Layer)是一种安全协议,用于在客户端和服务器之间建立加密的通信通道。
|
3月前
|
网络安全 数据安全/隐私保护
邮件Demo(SSL加密传输)
private final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; private String smtpServer; // SMTP服务器地址 private String port; // 端口 private String username; // 登录SMTP服务器的用户名 private String password; // 登录SMTP服务器的密码 private List<String> recipients = new ArrayList<String>(); // 收件人地址集合
31 0
|
4月前
|
安全 网络安全 数据安全/隐私保护
SSL加密
【5月更文挑战第9天】SSL加密
33 1