KESTREL WEB SERVER

A reverse proxy scenario exists when there are multiple apps that share the same IP and port running on a single server. Kestrel doesn’t support this scenario because Kestrel doesn’t support sharing the same IP and port among multiple processes. When Kestrel is configured to listen on a port, Kestrel handles all of the traffic for that port regardless of requests’ host header. A reverse proxy that can share ports has the ability to forward requests to Kestrel on a unique IP and port.

Even if a reverse proxy server isn’t required, using a reverse proxy server might be a good choice:

  • It can limit the exposed public surface area of the apps that it hosts.
  • It provides an additional layer of configuration and defense.
  • It might integrate better with existing infrastructure.
  • It simplifies load balancing and SSL configuration. Only the reverse proxy server requires an SSL certificate, and that server can communicate with your app servers on the internal network using plain HTTP.

INSTALL DOTNET

1. Register the Microsoft Product key as trusted.

curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg

2. Set up the desired version host package feed.

sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
microsoft-ubuntu-xenial-prod > ubuntu 16.04.5 LTS
microsoft-ubuntu-bionic-prod > ubuntu 18.04 LTS
microsoft-ubuntu-cosmic-prod > ubuntu 18.10 LTS

3. Update software package index.

sudo apt-get update

4. Install .NET Core.

sudo apt-get install dotnet-sdk-2.2

here are the some samples as below

dotnet-sdk-2.1.100dotnet-sdk-2.1.200dotnet-sdk-2.1.4
dotnet-sdk-2.1.101dotnet-sdk-2.1.201dotnet-sdk-2.2

INSTALL NET CORE AND WEB SERVER

Step 1

  1. sudo apt-get install apache2
  2. sudo a2enmod proxy                                     (Enable Apache2 Proxy Modules)
  3. sudo a2enmod proxy_http                          (Enable Apache2 Proxy Modules)
  4. sudo systemctl restart apache2.service
  5. sudo nano /etc/apache2/sites-available/kayacetinsu.com.conf

run the commands above to create a new site configuration file called.

<VirtualHost *:80>
    #ProxyPreserveHost On
    ProxyPass / http://localhost:7001/
    ProxyPassReverse / http://localhost:7001/
    ServerName kayacetinsu.com
    ServerAlias www.kayacetinsu.com
    ErrorLog ${APACHE_LOG_DIR}/error-kayacetinsu.com.log
    CustomLog ${APACHE_LOG_DIR}/access-kayacetinsu.com.log combined
</VirtualHost>

http://localhost:7001 –> accept only local connections

http://*:7001 –> accept remote connections

http://0.0.0.0:7001 –> accept remote connections

  1. sudo a2ensite kayacetinsu.com.conf                            (enable the site configuration)
  2. sudo systemctl reload apache2.service
  3. You may want to disable the default site configuration for Apache2 site configuration file if there is a confliction
sudo a2dissite 000-default.conf under /etc/apache2/sites-available/

Step 2

  1. dotnet new mvc -n coretest -o ~/coretest
  2. sudo nano ~/coretest/Program.cs
public static void Main(string[] args)
{
    CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>

    WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseUrls("http://localhost:7001")
        .UseConfiguration(new ConfigurationBuilder()
            .AddCommandLine(args)
            .Build()
        )
        .UseStartup<Startup>();

     3. dotnet publish -c Release -o ~/coretest/publish

Step 3

  1. sudo nano /etc/systemd/system/kestrel-coretest.service
[Unit]
Description=Example ASP -NET Web Application running on Ubuntu 16.04

[Service]
WorkingDirectory=/home/kaya/coretest/publish
ExecStart=/usr/bin/dotnet /home/kaya/coretest/publish/coretest.dll
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-demo
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

     2. sudo systemctl enable kestrel-coretest.service
     3. sudo systemctl start kestrel-coretest.service

Step 4)

Instead of step 3 we can run the command line to start listening the application.

To get this command line –>  in program.cs use “.UseConfiguration”

dotnet run –-urls "http://localhost:7001"

Step 5

  1. sudo nano /etc/hosts
    127.0.0.1 kayacetinsu.com

     2. sudo systemd-resolve –flush-caches

REFERENCES

Kestrel web server implementation in ASP.NET Core
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *