diff --git a/Server.Installer/Models/WebServerType.cs b/Server.Installer/Models/WebServerType.cs index e7ad4db3a..ac488ca81 100644 --- a/Server.Installer/Models/WebServerType.cs +++ b/Server.Installer/Models/WebServerType.cs @@ -14,6 +14,7 @@ public enum WebServerType UbuntuNginx, CentOsCaddy, CentOsNginx, + Rhel8Nginx, IisWindows } } diff --git a/Server.Installer/Program.cs b/Server.Installer/Program.cs index ca418323d..09b2a12dd 100644 --- a/Server.Installer/Program.cs +++ b/Server.Installer/Program.cs @@ -103,6 +103,7 @@ public static async Task Main(string[] args) "Nginx on Ubuntu", "Caddy on CentOS", "Nginx on CentOS", + "Nginx on RHEL8" "IIS on Windows Server 2016+"); if (Enum.TryParse(webServerType, out var result)) diff --git a/Server.Installer/Resources/RHEL8_Nginx_Install.sh b/Server.Installer/Resources/RHEL8_Nginx_Install.sh new file mode 100644 index 000000000..8d3819c2b --- /dev/null +++ b/Server.Installer/Resources/RHEL8_Nginx_Install.sh @@ -0,0 +1,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 diff --git a/Server.Installer/Server.Installer.csproj b/Server.Installer/Server.Installer.csproj index 107a54c52..30468b27e 100644 --- a/Server.Installer/Server.Installer.csproj +++ b/Server.Installer/Server.Installer.csproj @@ -18,6 +18,7 @@ + @@ -26,6 +27,7 @@ + diff --git a/Server.Installer/Services/ServerInstaller.cs b/Server.Installer/Services/ServerInstaller.cs index 5540530a7..2464709e2 100644 --- a/Server.Installer/Services/ServerInstaller.cs +++ b/Server.Installer/Services/ServerInstaller.cs @@ -135,6 +135,7 @@ private async Task LaunchExternalInstaller(CliParams cliParams) WebServerType.UbuntuNginx => "Ubuntu_Nginx_Install.sh", WebServerType.CentOsCaddy => "CentOS_Caddy_Install.sh", WebServerType.CentOsNginx => "CentOS_Nginx_Install.sh", + WebServerType.Rhel8Nginx => "RHEL8_Nginx_Install.sh", WebServerType.IisWindows => "IIS_Windows_Install.ps1", _ => throw new Exception("Unrecognized reverse proxy type."), };