-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-nginx.sh
45 lines (36 loc) · 1.13 KB
/
setup-nginx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Define variables
SITE_NAME="astro-sqlite-tts-feed"
DOMAIN_NAME="tts-feed.larryhudson.io"
APP_PORT="3000"
APP_DIR="/var/www/${SITE_NAME}"
NGINX_CONF_FILE_PATH="/etc/nginx/sites-available/${DOMAIN_NAME}"
# Create a new nginx configuration file for the site
sudo tee ${NGINX_CONF_FILE_PATH} <<EOF
server {
listen 80;
server_name ${DOMAIN_NAME};
location / {
proxy_pass http://127.0.0.1:${APP_PORT};
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
location /static/ {
if (\$arg_password != "ENTER_PASSWORD_HERE")
return 403;
}
alias ${APP_DIR}/static/;
autoindex off;
}
}
EOF
# Enable the new site
sudo ln -s ${NGINX_CONF_FILE_PATH} /etc/nginx/sites-enabled/
# Test the configuration and reload Nginx
sudo nginx -t && sudo systemctl reload nginx
# At this point, should wait for the site to start working
# Request a new SSL certificate using the nginx plugin
sudo certbot --nginx -d ${DOMAIN_NAME}