-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx_install.sh
executable file
·65 lines (52 loc) · 1.92 KB
/
nginx_install.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
release=$(lsb_release --codename | cut -f2)
echo "deb https://nginx.org/packages/ubuntu/ $release nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb-src https://nginx.org/packages/ubuntu/ $release nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt-get update
sudo apt-get install nginx
echo "What is the frontend static path? (ex: /home/user/frontend-project)"
read FRONTEND
echo "What is the server port? (ex: 3000)"
read PORT
echo "What is the SSL KEY path? (ex: /home/user/project/file.key)"
read SSLKEY
echo "What is the SSL CERT path? (ex: /home/user/project/file.crt)"
read SSLCERT
sudo cat <<EOF >> /etc/nginx/conf.d/mginstitute.conf
server {
server_name _;
listen localhost:443 ssl;
ssl_certificate $SSLCERT;
ssl_certificate_key $SSLKEY;
ssl_session_timeout 30m;
ssl_session_cache shared:SSL:400k;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
server_tokens off;
charset utf-8;
gzip on;
gzip_min_length 0;
gzip_proxied any;
gzip_types text/plain text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml image/gif, image/png, image/jpeg image/webp;
location /api/ {
proxy_pass https://localhost:$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 ~* ^.+\.(html|css|js|pdf|jpg|jpeg|png|svg) {
root $FRONTEND;
}
location ~* ^\/?$ {
root $FRONTEND;
try_files /index.html =404;
}
location / {
root $FRONTEND;
try_files \$uri.html \$uri \$uri/index.html \$uri/ =404;
}
}
EOF
sudo nginx -s reload
echo "NGinX installed and configured to act as a reverse proxy from port 443 to $HOST:$PORT."