nginx/nginx.sh

99 lines
1.9 KiB
Bash
Raw Normal View History

2024-06-14 07:14:42 +00:00
#!/usr/bin/env bash
2024-12-02 08:41:11 +00:00
unset backup_port addurl adddomains
clear
2024-06-14 07:14:42 +00:00
# Fill in the following variables
2024-12-02 08:41:11 +00:00
eff_email_address=
2024-06-14 07:14:42 +00:00
appname=
2024-12-02 08:41:11 +00:00
subdomain=
2024-06-14 07:14:42 +00:00
domain=
2024-12-02 08:41:11 +00:00
adddomains=()
host=
2024-06-14 07:14:42 +00:00
port=
2024-12-02 08:41:11 +00:00
backup_port=
2024-06-14 07:14:42 +00:00
2024-12-02 08:41:11 +00:00
if [ ${subdomain} ]
2024-06-14 07:14:42 +00:00
then
2024-12-02 08:41:11 +00:00
url=${subdomain}.${domain}
else
url=${domain}
fi
for i in ${adddomains[@]}
do
addurl+=(${subdomain}.${i})
done
sudo rm -f /etc/nginx/conf.d/${appname}.conf
if [ ${backup_port} ]
then
sudo tee /etc/nginx/conf.d/${appname}.conf >/dev/null <<- conf
upstream ${appname} {
server ${host}:${port};
server 127.0.0.1:${backup_port} backup;
}
conf
else
sudo tee /etc/nginx/conf.d/${appname}.conf >/dev/null <<- conf
upstream ${appname} {
server ${host}:${port};
}
conf
2024-06-14 07:14:42 +00:00
fi
2024-12-02 08:41:11 +00:00
sudo tee -a /etc/nginx/conf.d/${appname}.conf >/dev/null <<- conf
2024-06-14 07:14:42 +00:00
server {
server_name ${url};
include local/http_upgrade;
location / {
2024-12-02 08:41:11 +00:00
proxy_pass http://${appname};
2024-06-14 07:14:42 +00:00
include local/proxy_params;
error_log /var/log/nginx/${appname}_error.log;
access_log /var/log/nginx/${appname}_access.log;
}
}
2024-12-02 08:41:11 +00:00
2024-06-14 07:14:42 +00:00
conf
2024-12-02 08:41:11 +00:00
sudo certbot --nginx --non-interactive --agree-tos --no-eff-email -m ${eff_email_address} -d ${url} \
--staple-ocsp --hsts --no-redirect
for url in ${addurl[@]}
do
sudo tee -a /etc/nginx/conf.d/${appname}.conf >/dev/null <<- conf
server {
server_name ${url};
include local/http_upgrade;
location / {
proxy_pass http://${appname};
include local/proxy_params;
error_log /var/log/nginx/${appname}_error.log;
access_log /var/log/nginx/${appname}_access.log;
}
}
conf
2024-06-14 07:14:42 +00:00
sudo certbot --nginx --non-interactive --agree-tos --no-eff-email -m ${eff_email_address} -d ${url} \
--staple-ocsp --hsts --no-redirect
2024-12-02 08:41:11 +00:00
done
2024-06-14 07:14:42 +00:00
2024-12-02 08:41:11 +00:00
sudo sed -e '/listen 80/d' \
-e '/listen 443/a\
listen 443 quic;\
listen [::]:443 ssl;\
listen [::]:443 quic;\
' -i /etc/nginx/conf.d/${appname}.conf
sudo systemctl reload nginx.service