How to do balancing on blazor server using Nginx? - nginx

I have a website on blazor server that will need to scale in the future i.e. there will be several servers. How to do balancing on blazor server using Nginx? In this case, it is necessary that the session is also saved, i.e. did not throw out in case of turning off one of the servers.

Microsoft describes how to load-balance on Linux using NGINX on the following page:
ASP.NET Core SignalR hosting and scaling

Related

.Net 6 API - can't get data -> ERR_CERT_AUTHORITY_INVALID

I run a .Net 6 API on my Raspberry PI. I can get data from this API using the browser “https://192.168.178.51:7001/swagger/” . Also getting data from entering the url “https://192.168.178.51:7001/api/status/” returns the expected values. So the API is working so far. But when I try to get data from my Blazor WASM App using HTTPClient I get no data. Inspect the browser shows the following message:
GET https://192.168.178.51:7001/api/Status net::ERR_CERT_AUTHORITY_INVALID
How can I fix this? Do I have to install a SSL Certificate? How to do this for a self contained API?
You will need, at minima, a self-sign certificate. Then you will need to let your browser accept a self-sign.(Advance, Proceed to ServerIp)
Now, I do not know what OS you are using in your Raspberry, but for a Beaglebone(similar to Raspberry Pi) with Debian and nginx, here is the procedure
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-nginx-on-debian-10
You will need the same kind of steps for which ever OS and webserver(Apache, nginx...Kestrel?).
Using a reverse proxy will be the solution, as described here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-6.0
Quote from the article:
Kestrel is great for serving dynamic content from ASP.NET Core. However, the web serving capabilities aren't as feature rich as servers such as IIS, Apache, or Nginx. A reverse proxy server can offload work such as serving static content, caching requests, compressing requests, and HTTPS termination from the HTTP server.
Using a reverse proxy I can set a certificate.

Running Kestrel with http/2

I need to support http/2 on my web app running inside a container and I'm having a hard time to configure Kestrel to run http/2 with my self-signed certificates.
What I want to ask is, is there a difference running Kestrel behind Nginx and handling all http/2 communication on Nginx and supporting http/2 at Kestrel level?
To summarize there are two options:
1. Run Asp.Net Core app behind Nginx and on http. Http/2 is handled by Nginx.
2. Run Asp.Net Core with http/2 support.
Which way should I prefer?
For any production environment, it is better to use a dedicated reverse proxy (like Nginx) instead of exposing the application directly. They are more specialized for this purpose and usually provide better security and performance. ASP.NET Core documentation also recommends using separate reverse proxy for these reasons https://learn.microsoft.com/en-US/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1

"Server" response header for Kestrel behind IIS

If I host my Kestrel-based ASP.NET Core website with UseIISIntegration behind IIS, should the Server response header still say that I'm using Kestrel? Because it seems that it is:
Is it a correct behavior?
Short answer: Yes, it should still report the application as hosted by Kestrel.
When you use IIS to host an ASP.NET Core application, you're really using IIS as a reverse proxy to Kestrel. This is the approach recommended by the documentation:
If you intend to deploy your application on a Windows server, you should run IIS as a reverse proxy server that manages and proxies requests to Kestrel.
An incoming request will be handled first by IIS, and then passed on to Kestrel, like this:
Web -> IIS -> ASP.NET Core module -> Kestrel
So it's still accurate to say that Kestrel is the server handling the request. IIS is just sitting in front, helping Kestrel deal with the incoming traffic. You can check whether the site has been set up and assigned to an app pool in the IIS Manager if you want to determine whether it's using IIS (which should be the default).
Not exactly the answer to the question, but since Google gave me this related answer to my question it might help some people:
To remove this "server" header, an option has been added to the Kestrel Startup Options, so in program.cs you can remove it by adding the following option:
.UseKestrel(o => { o.AddServerHeader = false; })
Documentation (quite poor)

Can Nginx be used instead of Gunicorn to manage multiple local OpenERP worker servers?

I'm currently using Nginx as a web server for Openerp. It's used to handle SSL and cache static data.
I'm considering extending it's use to also handle fail over and load balancing with a second server, using the upstream module.
In the process, it occurred to me that Nginx could also do this on multiple Openerp servers on the same machine, so I can take advantage of multiple cores. But Gunicorn seems to the the preferred tool for this.
The question is: can Nginx do a good job handling traffic to multiple local OpenERP servers, bypassing completely the need for Gunicorn?
Let first talk what they both are bascially.
Nginx is a pure web server that's intended for serving up static content and/or redirecting the request to another socket to handle the request.
Gunicorn is based on the pre-fork worker model. This means that there is a central master process that manages a set of worker processes. The master never knows anything about individual clients. All requests and responses are handled completely by worker processes.
If you see closely Gunicorn is Designed from Unicron, Follow the link for the detail more diff
which show the ngix and unicrom same model work on Gunicron also.
nginx is not a "pure web server" :) It's rather a web accelerator capable of doing load balancing, caching, SSL termination, request routing AND static content. A "pure web server" would be something like Apache - historically a web server for static content, CGIs and later for mod_something.

How do I configure webfarm for a simple asp.net demo application

I am just making a demo application and want to configure asp.net to use webfarm. How can I do so?
I have already configured my session mode to use SQL Server and it works perfectly. What should I do next? I am using Windows 7, SQL Server 2008 and Asp.Net 4.0 webforms.
You need multiple machines - set up the application on both of them and configure both web sites to have a common host name/header. You also need to setup a common machine key for encrypting view-state etc. In real web farm setup, you will have a s/w or h/w load balancer that will be route requests to either server based on load. In case, you don't have a load balancer then use your local hosts file to resolve the common host name - for example, for first couple of request, use machine 1 and then switch it to machine 2 for next few and so on.

Resources