-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathRHEL8_Nginx_Install.sh
More file actions
156 lines (124 loc) · 3.96 KB
/
Copy pathRHEL8_Nginx_Install.sh
File metadata and controls
156 lines (124 loc) · 3.96 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
DOTNETVERSION="5.0"
echo "Thanks for trying Remotely!"
echo
Args=( "$@" )
ArgLength=${#Args[@]}
for (( i=0; i<${ArgLength}; i+=2 ));
do
if [ "${Args[$i]}" = "--host" ]; then
HostName="${Args[$i+1]}"
elif [ "${Args[$i]}" = "--approot" ]; then
AppRoot="${Args[$i+1]}"
fi
done
if [ -z "$AppRoot" ]; then
read -p "Enter path where the Remotely server files should be installed (typically /var/www/remotely): " AppRoot
if [ -z "$AppRoot" ]; then
AppRoot="/var/www/remotely"
fi
fi
if [ -z "$HostName" ]; then
read -p "Enter server host (e.g. remotely.yourdomainname.com): " HostName
fi
echo "Using $AppRoot as the Remotely website's content directory."
dnf update
dnf -y install curl
dnf -y install gnupg
# Install other prerequisites.
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
dnf -y install dnf-utils
dnf -y install unzip
dnf -y install acl
dnf -y install glibc-devel
dnf -y install libgdiplus
dnf -y install nginx
# Install Dotnet
dnf -y install dotnet-host dotnet-hostfxr-$DOTNETVERSION dotnet-runtime-$DOTNETVERSION
# Set permissions on Remotely files.
setfacl -R -m u:nginx:rwx $AppRoot
chown -R nginx:nginx $AppRoot
chmod +x "$AppRoot/Remotely_Server"
# Install Nginx
dnf -y install nginx
systemctl start nginx
# Configure Nginx
nginxConfig="server {
listen 80;
server_name $HostName *.$HostName;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection close;
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
location /_blazor {
proxy_pass http://localhost:5000;
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 /AgentHub {
proxy_pass http://localhost:5000;
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 /ViewerHub {
proxy_pass http://localhost:5000;
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 /CasterHub {
proxy_pass http://localhost:5000;
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;
}
}"
echo "$nginxConfig" > /etc/nginx/conf.d/remotely.conf
# Test config.
nginx -t
# Reload.
nginx -s reload
# Create service.
serviceConfig="[Unit]
Description=Remotely Server
[Service]
WorkingDirectory=$AppRoot
ExecStart=/usr/bin/dotnet $AppRoot/Remotely_Server.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=remotely
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target"
echo "$serviceConfig" > /etc/systemd/system/remotely.service
# Enable service.
systemctl enable remotely.service
# Start service.
systemctl start remotely.service
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
# Install Certbot and get SSL cert.
dnf -y install python3-certbot-nginx
# SELinux policies
setsebool -P httpd_can_network_connect 1
certbot --nginx