修改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 #!/bin/bash
declare domain_str=$2
if ! command -v socat &> /dev/null; then if ! command -v socat &> /dev/null; then
if [[ -f "/usr/bin/apt-get" ]];then if [[ -f "/usr/bin/apt-get" ]];then
apt-get update -y 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" curl https://get.acme.sh | sh -s "email=$mail"
fi fi
declare domain_str=''
echo "请输入需要申请SSL证书的域名" if [[ $domain_str ]];then
while(true);do echo "请输入需要申请SSL证书的域名"
read -p "不输入退出添加:" domain while(true);do
if [[ -z $domain ]];then read -p "不输入退出添加:" domain
break if [[ -z $domain ]];then
elif [[ ! $domain =~ [\w+\.]+ ]];then break
echo "域名不合法" elif [[ ! $domain =~ [\w+\.]+ ]];then
exit echo "域名不合法"
else exit
domain_str="$domain_str -d $domain" else
domain_str="$domain_str -d $domain"
fi
done
if [[ -z $domain_str ]]; then
echo "需要添加的域名不能为空"
exit
fi fi
done
if [[ -z $domain_str ]]; then
echo "需要添加的域名不能为空"
exit
fi fi
declare pick_mode declare pick_mode
@ -57,6 +61,17 @@ case $pick_mode in
declare mode declare mode
if command -v nginx &> /dev/null; then if command -v nginx &> /dev/null; then
mode="nginx" 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 elif command -v apache &> /dev/null; then
mode="apache" mode="apache"
else else
@ -65,6 +80,7 @@ case $pick_mode in
echo "请到服务器将80和443端口开启,将域名解析到本机" echo "请到服务器将80和443端口开启,将域名解析到本机"
read -p "解析完成请回车:" read -p "解析完成请回车:"
eval "${HOME}/.acme.sh/acme.sh --issue ${domain_str} --${mode}" eval "${HOME}/.acme.sh/acme.sh --issue ${domain_str} --${mode}"
rm /etc/nginx/conf.d/test
;; ;;
'2') '2')
declare pick=0 declare pick=0

View File

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

View File

@ -17,5 +17,5 @@ echo "========Web========"
read -p "请输入要使用的功能:" pick read -p "请输入要使用的功能:" pick
if [[ "${pick}" =~ [1-${#print_array[*]}] ]];then 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 fi

2
Run.sh
View File

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