为nginx创建自签名证书

2022/8/4 5:22:54

本文主要是介绍为nginx创建自签名证书,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#!/bin/sh

 

# create self-signed server certificate:

 

read -p "Enter your domain [www.example.com]: " DOMAIN

 

echo "Create server key..."

 

openssl genrsa -des3 -out $DOMAIN.key 1024

 

echo "Create server certificate signing request..."

 

SUBJECT="/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=$DOMAIN"

 

openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr

 

echo "Remove password..."

 

mv $DOMAIN.key $DOMAIN.origin.key

openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key

 

echo "Sign SSL certificate..."

 

openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt

 

echo "TODO:"

echo "Copy $DOMAIN.crt to /etc/nginx/ssl/$DOMAIN.crt"

echo "Copy $DOMAIN.key to /etc/nginx/ssl/$DOMAIN.key"

echo "Add configuration in nginx:"

echo "server {"

echo "    ..."

echo "    listen 443 ssl;"

echo "    ssl_certificate     /etc/nginx/ssl/$DOMAIN.crt;"

echo "    ssl_certificate_key /etc/nginx/ssl/$DOMAIN.key;"

echo "}"



这篇关于为nginx创建自签名证书的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程