SSL测试证书

1. tomcat

1.1 生成

  • keytool -genkey -alias tomcat -keyalg RSA -keystore tomcat.keystore -validity 365
    过程中按照要求输入密码和其他国家等信息(可以随便填)

1.2 配置

  • 在tomcat的conf/server.xml中添加一下内容, 修改路径和密码
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    		   maxThreads="150" scheme="https" secure="true"
    		   keystoreFile="/path/to/tomcat.keystore"
    		   keystorePass="*******"
    		   clientAuth="false" sslProtocol="TLS" />
    
  • 重启tomcat生效

2. nginx

2.1 生成

  • 私钥: openssl genrsa -out key.pem 2048
  • 证书: openssl req -new -key key.pem -out csr.pem, 其中内容皆可回车跳过
  • 签名: openssl x509 -req -in csr.pem -out cert.pem -signkey key.pem -days 365

2.2 配置

  • 在编译安装前配置时候需要加上./configure --with-http_ssl_module
  • 按照以下内容修改conf/nginx/conf文件, 记录修改路径
    server {
    	listen       443 ssl;
    	server_name  localhost;
    
    	ssl_certificate /path/to/cert.pem;
    	ssl_certificate_key /path/to/key.pem;
    }
    
  • 重载nginx生效: ./sbin/nginx -s reload

3. 参考

posted @ 2024-05-24 17:04  Codorld  阅读(14)  评论(0编辑  收藏  举报