openssl给内网IP生成ca证书(ssl证书)

一、要使用 OpenSSL 为内网 IP 生成 CA 证书,您需要遵循以下步骤:

1、创建一个存放证书的文件夹

mkdir /opt/zhengshu

 注意:大家自己按照自己的目录创建就行,我的直接放在/opt目录下了。

2、生成私钥和证书请求

openssl req -newkey rsa:2048 -nodes -keyout ca.key -out ca.csr

 注意:申请的时候会让大家填一些参数,下面是参数说明及示例:

字段    字段含义                    示例
/C=     Country 国家                CN
/ST=    State or Province 省        beijing
/L=     Location or City 城市       beijing
/O=     Organization 组织或企业     stars-mine
/OU=    Organization Unit 部门      stars-mine
/CN=    Common Name 是证书拥有者名称  172.xx.xx.xx
#下面这两个参数,大家直接回车跳过就行
A challenge password []:
An optional company name []:

3、自签署证书

openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

 4、生成服务器证书

openssl genrsa -out server.key 2048

openssl req -new -key server.key -out server.csr

 注意:这一步也会输入参数,要和上一次输入的保持一致 

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365

 5、生成客户端证书

openssl genrsa -out client.key 2048

 

openssl req -new -key client.key -out client.csr

 

 注意:这一步也会输入参数,要和前两次输入的保持一致 

openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365

 6、到此,所有证书就生成完毕

 二、证书配置

1、配置示例(Apache):

<VirtualHost *:443>
    ServerName example.com
    SSLEngine on
    SSLCertificateFile /path/to/server.crt
    SSLCertificateKeyFile /path/to/server.key
    SSLCACertificateFile /path/to/ca.crt
    ...
</VirtualHost>

2、配置示例(Nginx):

server {
        listen       80;
	    listen       443 ssl;
        server_name  172.21.10.101;
	    ssl_certificate /opt/server.crt;
    	ssl_certificate_key /opt/server.key;
	    if ($scheme = http) {
           return 301 https://$host$uri?$args;
        }

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://172.xx.xx.xx:9000/xxx/xxx/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

3、配置示例(Tomcat):

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
           maxThreads="150" scheme="https" secure="true"
           keystoreFile="/path/to/server.keystore" keystorePass="password"
           truststoreFile="/path/to/ca.crt" truststorePass="password"
           clientAuth="true" sslProtocol="TLS"/>

注意:第一步的这些命令将生成一个名为 ca.crt 的 CA 证书,一个名为 server.crt 的服务器证书以及一个名为 client.crt 的客户端证书。您可以将这些证书分发给您的应用程序和客户端,以启用 SSL/TLS 加密。 

三、常见问题处理

1、内网IP配置了SSL证书后,https无法访问

解决方法:查看服务器防火墙是否都关闭,一定要关闭防火墙

service iptables status

systemctl status firewalld

 状态说明:

出现Active: active (running)切高亮显示则表示是启动状态。

出现 Active: inactive (dead)灰色表示停止,看单词也行。

猜你喜欢

转载自blog.csdn.net/wd520521/article/details/129832318