This repository was archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenableSSL.sh
More file actions
executable file
·82 lines (62 loc) · 1.88 KB
/
enableSSL.sh
File metadata and controls
executable file
·82 lines (62 loc) · 1.88 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -e
if [[ $# -ne 1 ]]; then
echo "No target host specified."
exit 1
fi
IFS='@' read -ra PARTS <<< "$1"
if [[ ${#PARTS[*]} -ne 2 ]]; then
echo "Required target format it \"user@host[:port]\"."
exit 1
fi
TARGET_USER=${PARTS[0]}
IFS=':' read -ra PARTS <<< "${PARTS[1]}"
if [[ ${#PARTS[*]} -eq 1 ]]; then
TARGET_DOMAIN=${PARTS[0]}
TARGET_PORT=22
elif [[ ${#PARTS[*]} -eq 2 ]]; then
TARGET_DOMAIN=${PARTS[0]}
TARGET_PORT=${PARTS[1]}
fi
ssh $TARGET_USER@$TARGET_DOMAIN -p $TARGET_PORT <<EOF
set -e
sudo snap install --classic certbot
sudo apt update
sudo apt upgrade -y
sudo apt install nginx -y
sudo systemctl stop nginx
sudo rm -rf /etc/nginx/sites-enabled/*
sudo certbot certonly --standalone --non-interactive --agree-tos --email rsatom+certbot@gmail.com -d $TARGET_DOMAIN
sudo tee /etc/nginx/conf.d/WebRTSPProxy.conf > /dev/null <<'EOF2'
server {
server_name $TARGET_DOMAIN;
location / {
proxy_pass http://localhost:6554/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
}
error_page 497 https://\$server_name:\$server_port\$request_uri;
listen [::]:6555 ssl ipv6only=on;
listen 6555 ssl;
ssl_certificate /etc/letsencrypt/live/$TARGET_DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$TARGET_DOMAIN/privkey.pem;
}
server {
server_name $TARGET_DOMAIN;
location / {
proxy_pass http://localhost:6654/;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
}
error_page 497 https://\$server_name:\$server_port\$request_uri;
listen [::]:6655 ssl ipv6only=on;
listen 6655 ssl;
ssl_certificate /etc/letsencrypt/live/$TARGET_DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$TARGET_DOMAIN/privkey.pem;
}
EOF2
sudo nginx -t
sudo systemctl start nginx
EOF