LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

[点晴永久免费OA]使用OpenSSL自签发SSL证书实现局域网内网站https方式访问

admin
2025年9月15日 22:40 本文热度 59
在最近的项目中遇到因为不是通过https方式访问网站,导致等保测评无法通过,被打上了高风险的标签,而高风险为一票否决项,因此这是必须整改的内容,客户网络为内部网络环境,从网络环境和实际需求看完全可以通过OpenSSL进行自签发SSL证书来实现这一个目的。

下边就来看下如何操作的,首先你需要一台Linux服务器并且已经安装了OpenSSL工具,如果没有安装的可以使用yum/apt-get一键安装,安装完成后操作如下:
1、使用nginx -V查看是否支持SSL证书
2、找到一台服务器,假如这台服务器就是CA证书服务器,我这里是用的Linux服务器,具体版本(Centos7.9),进入/etc/pki/CA/目录,执行如下命令,将umask设置为077权限,然后使用OpenSSL生成私钥。
umask 077;openssl genrsa -out private/cakey.pem 2048
3、执行如下命令生成根证书并且创建两个文件,分别是index.txt和serial,index.txt使用touch创建即可,serial中输入01。
生成自签证书
openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
会让你填写一些信息,根据提示填写就好了
[root@security CA]# openssl req -new -x509 -key httpd.key -out cacert.pem -days 3650You are about to be asked to enter information that will be incorporatedinto 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 blankFor 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) []:SC   #省份Locality Name (eg, city) [Default City]:CD  #城市Organization Name (eg, company) [Default Company Ltd]:chengdu   #单位名称Organizational Unit Name (eg, section) []:yunwei  #部门名称Common Name (eg, your name or your server's hostname) []:www.ca.cn #填一个域名Email Address []:12345678@qq.com    #邮箱
4、找到另外一台服务器,我这里只有一台服务器,到另外一个目录创建相关的证书,假如是/usr/ssl目录
生成私钥
执行命令生成证书签署请求,其中hostname项为网站域名,其他内容都和CA证书一致
openssl req -new -key server.key -out server.csr
5、用之前生成的CA证书对证书签署请求进行签名,得到服务端证书
openssl ca -in /usr/ssl/server.csr -out server.crt -days 3650
这就把证书签好了,然后我们可以在index.txt和serial文件中看下相关数据
6、然后就可以去nginx或者Apache httpd中配置HTTPS方式访问了
将签署的证书签署请求、服务端的key文件都放到nginx配置目录下:/etc/nginx/下,或者可以自建一个目录用于存放ssl证书文件。
配置NGINX配置文件nginx.conf
user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;
events {    worker_connections 1024;}
http {    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 4096;
    include             /etc/nginx/mime.types;    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.    # See http://nginx.org/en/docs/ngx_core_module.html#include    # for more information.    include /etc/nginx/conf.d/*.conf;
    server {        listen       8888;        listen       [::]:8888;        server_name  www.mytest.cn;        root         /var/www/html;        return 301 https://www.mytest.cn:9443;   #将http请求重定向到https#        # Load configuration files for the default server block.#        include /etc/nginx/default.d/*.conf;#        #        location ~ \.php$ {#        fastcgi_pass   127.0.0.1:9000;#        fastcgi_index  index.php;#        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;#        include        fastcgi_params;#        }##        error_page 404 /404.html;#        location = /404.html {#        }##        error_page 500 502 503 504 /50x.html;#        location = /50x.html {#        }   }
# Settings for a TLS enabled server.#    server {        listen       9443 ssl;        listen       [::]:9443 ssl;        server_name  www.mytest.cn;        root         /var/www/html;
        ssl_certificate "/etc/nginx/ssl/server.crt";        ssl_certificate_key "/etc/nginx/ssl/server.key";        ssl_session_cache shared:SSL:1m;        ssl_session_timeout  10m;        ssl_ciphers HIGH:!aNULL:!MD5;        ssl_prefer_server_ciphers on;##        # Load configuration files for the default server block.        location ~ \.php$ {            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;            include        fastcgi_params;            }
        include /etc/nginx/default.d/*.conf;        error_page 404 /404.html;            location = /40x.html {        }
        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }    }
}
配置完成后使用nginx -s reload重新加载配置,让其生效,然后配置本地证书文件和hosts
将第三步生成的CA服务器需要对外公开的证书文件cacert.pem复制到电脑本地,后缀名改为crt格式,然后双击安装证书,将其导入到电脑本地
显示导入成功即可,由于www.mytest.cn这个域名没有在DNS域名服务商哪里注册,所以需要我们自己在hosts文件中添加域名解析地址,Windows电脑在C:\Windows\System32\drivers\etc下,先将hosts文件拖出来到桌面,然后修改添加如下内容在拖进去
你的服务器ip地址  www.mytest.cn
修改完成后就可以试着用https方式访问了,由于我使用了天翼云的ECS云主机,但是天翼云如果使用80或者443端口需要进行备案,所以我这里使用9443作为网页端口。
抓个包看下,数据被加密处理。
这就是使用openssl工具自签发证书解决网页未使用https访问问题。


阅读原文:原文链接


该文章在 2025/9/16 11:56:41 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved