(LINUX) LINUX (2021)

Deploy .NET Core on Ubuntu, demonize Kestrel, run Nginx as reversy proxy, separate Backend and Frontend

This is short implementation of my old articles Deploy ASP.NET Core application from scratch (install and tune SSH/VNC/FTP/NGINX/Daemon/Db), common idea the same, but this is another site, all screens and description I show in another circumstances.

Of course, deployment start from installation .NET CORE - https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu, of course need to install Nginx.



This was empty step and we go ahead to more interesting steps. I split Frontend and Backend to different port, look to Frontend firstly.



Also my frontend has additional endpoint for SignalR, look to definition of it, I use additional suffix CS for perform it.



My backend has complex and sophisticated structure including my own service locator, Swagger and so on, but main point for father understanding is definition of SignalR endpoint.



I have copied Frontend to folder Blazor and Backend to folder API.



Next point is simple try to start application under Kestrel, in my case


# /usr/bin/dotnet /var/www/development/Blazor/Frontend1.dll
# tail -n 200 /var/log/syslog

Result of first start is usually unexpected, including full Ubuntu shutdown.



But finally I see great log.



This means we ready to go to the next step - create two Service for simple restart Kesrel after site version will be updated. And of course when Kestrel will shutdown after error.


# cd /etc/systemd/system/
# sudo nano Frontend.service
# sudo nano Backend.service
 

In my case

[Unit]
Description=Frontend daemon

[Service]
WorkingDirectory=/var/www/development/Blazor/
ExecStart=/usr/bin/dotnet /var/www/development/Blazor/Frontend1.dll
Restart=always
RestartSec=10 
SyslogIdentifier=Frontend
User=root 
Environment=ASPNETCORE_ENVIRONMENT=Development

[Install]
WantedBy=multi-user.target

 
[Unit]
Description=Backend daemon

[Service]
WorkingDirectory=/var/www/development/API
ExecStart=/usr/bin/dotnet /var/www/development/API/CryptoChestNew.MicroServices.WebApi.dll
Restart=always
RestartSec=10 
SyslogIdentifier=Backend
User=root 
Environment=ASPNETCORE_ENVIRONMENT=Development

[Install]
WantedBy=multi-user.target 


This future allow me:

#sudo systemctl start/stop/status Frontend.service
#sudo systemctl start/stop/status Backendend.service

And, of course, after service was created need to allow it started after reboot.


#sudo systemctl enable Frontend.service
#sudo systemctl enable Backendend.service

And finally point is tune Nginx as reverse proxy.


In my case port 80 is busy for another site.


events {
  worker_connections  4096;  ## Default: 1024
}

http {
  include    mime.types;

  server {
        listen 80;
        listen [::]:80;

        root /var/www/cryptochest.io/html;
        index index.html index.htm index.nginx-debian.html;

        server_name cryptochest.io www.cryptochest.io;

        location / {
                try_files $uri $uri/ =404;
        }
  }
}


Therefore I must use another port. This is my solution for reverse proxy:

    server {
        listen       90;
        server_name  localhost;

        location /CS {
            #root   /var/www/development/API
            #Backend
            proxy_pass         http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            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 / {
            #root   /var/www/development/Blazor
            #Frontend
            proxy_pass         http://localhost:6000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            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;
        }
    }

Pay attention for port 5000 and 6000 and suffix CS defined in source code.





Comments ( )
Link to this page: //www.vb-net.com/DeployCore/Index.htm
< THANKS ME>