修改nginx和增加了acme的调用

This commit is contained in:
lsy 2024-09-25 15:10:40 +08:00
parent 95047371a8
commit 0f0a8edc6c
4 changed files with 63 additions and 28 deletions

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare domain_str=$2
if ! command -v socat &> /dev/null; then
if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y
@ -29,22 +31,24 @@ if [[ ! -f "${HOME}/.acme.sh/acme.sh" ]];then
curl https://get.acme.sh | sh -s "email=$mail"
fi
declare domain_str=''
echo "请输入需要申请SSL证书的域名"
while(true);do
read -p "不输入退出添加:" domain
if [[ -z $domain ]];then
break
elif [[ ! $domain =~ [\w+\.]+ ]];then
echo "域名不合法"
exit
else
domain_str="$domain_str -d $domain"
if [[ $domain_str ]];then
echo "请输入需要申请SSL证书的域名"
while(true);do
read -p "不输入退出添加:" domain
if [[ -z $domain ]];then
break
elif [[ ! $domain =~ [\w+\.]+ ]];then
echo "域名不合法"
exit
else
domain_str="$domain_str -d $domain"
fi
done
if [[ -z $domain_str ]]; then
echo "需要添加的域名不能为空"
exit
fi
done
if [[ -z $domain_str ]]; then
echo "需要添加的域名不能为空"
exit
fi
declare pick_mode
@ -57,6 +61,17 @@ case $pick_mode in
declare mode
if command -v nginx &> /dev/null; then
mode="nginx"
cat > "/etc/nginx/conf.d/test" << EOF
server {
listen 80; # 监听80端口
server_name ${domain}; # 服务器名称(本地)
location / {
root /usr/share/nginx/html; # 指定根目录
index index.html index.htm; # 默认页面
}
}
EOF
elif command -v apache &> /dev/null; then
mode="apache"
else
@ -65,6 +80,7 @@ case $pick_mode in
echo "请到服务器将80和443端口开启,将域名解析到本机"
read -p "解析完成请回车:"
eval "${HOME}/.acme.sh/acme.sh --issue ${domain_str} --${mode}"
rm /etc/nginx/conf.d/test
;;
'2')
declare pick=0

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare path_script=$1
if ! command -v nginx &> /dev/null; then
if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y
@ -32,17 +34,35 @@ case $pick in
declare ssl_domain=$(echo "${domain}" | awk '{print $1}')
echo "ssl证书地址"
echo "证书,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
read -p "请输入证书地址:" ssl_certificate
if [[ -z $ssl_certificate ]];then
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
fi
echo "密钥,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
echo "1.自动申请"
echo "2.手动输入"
read -p "请输入:" pick
if [[ $pick == 2 ]]; then
echo "证书,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
read -p "请输入证书地址:" ssl_certificate
if [[ -z $ssl_certificate ]];then
ssl_certificate="${HOME}/.acme.sh/${ssl_domain}_ecc/fullchain.cer"
fi
echo "密钥,默认 ${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
read -p "请输入密钥地址:" ssl_certificate_key
if [[ -z $ssl_certificate_key ]];then
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
read -p "请输入密钥地址:" ssl_certificate_key
if [[ -z $ssl_certificate_key ]];then
ssl_certificate_key="${HOME}/.acme.sh/${ssl_domain}_ecc/${ssl_domain}.key"
fi
else
declare ssl_domain=""
for i in ${domain} ; do
if ! [[ $i =~ [\w\.]+ ]]; then
echo "域名输入错误"
exit
fi
ssl_domain="${ssl_domain} -d ${i}"
done
bash "${path_script}/Config/Web/acme.sh"
fi
declare name
read -p "请输入配置文件名,默认为域名:" name
if [[ -z $name ]]; then
@ -54,7 +74,6 @@ case $pick in
echo "2.静态文件"
read -p "请选择:" pick
declare path
declare mode_pick
if [[ $pick == 2 ]]; then
read -p "请输入要代理的站点路径" path
cat > "/etc/nginx/sites-available/${name}.conf" << EOF
@ -174,7 +193,7 @@ server {
}
EOF
fi
ln -s "/etc/nginx/sites-available/${name}.conf" "/etc/nginx/sites-enabled"
ln -s "/etc/nginx/sites-available/${name}.conf" "/etc/nginx/sites-enabled" &> /dev/null
nginx -s reload &> /dev/null
echo "配置完成"
;;

View File

@ -17,5 +17,5 @@ echo "========Web========"
read -p "请输入要使用的功能:" pick
if [[ "${pick}" =~ [1-${#print_array[*]}] ]];then
bash "${path_script}/Config/${file_name}/${print_array[${pick}]}.sh"
bash "${path_script}/Config/${file_name}/${print_array[${pick}]}.sh" "${path_script}"
fi

2
Run.sh
View File

@ -23,7 +23,7 @@ do
done
echo "======Linux工具箱======"
read -p "请输入要使用的功能:" pick
if [[ "${pick}" -gt 0 && "${pick}" -le "${#pick_array[*]}" ]];then
if [[ "${pick}" =~ [1-${#pick_array[*]}] ]];then
clear
bash "${path_script}/Menus/${pick_array[$pick]}.sh" "$path_script"
else