Introduction

In this article, you will learn how to host your ASP.NET Core project on Linux with Jexus Web Server.

What is Jexus Web Server ?

Jexus is a free and high-performance Web Server and load balancing gateway on Linux platform . Jexus supports ASP.NET and ASP.NET CORE not only, but also supports PHP! It also contains reverse proxy, intrusion detection and other important functions.

Prerequisites

  1. Install .NET SDK on your server (Here I use CentOS 7.x).
  2. An existing ASP.NET Core application (Here I will create a new one).

Copy over your app

Run dotnet publish -c release from the dev environment to package an app into a self-contained directory that can run on the server.

Copy the publish folder to the server using whatever tool (SCP, FTP, etc.) integrates into your workflow.

Test the app, from the command line, run dotnet myapp.dll.

ASP.NET Core

OK, the app runs well.

You may notice that there are some warning messages but we don't need to worry about them. Jexus will help us to handle this!

Install Jexus

  1. curl https://jexus.org/release/x64/install.sh | sh

Note

When you install Jexus, your account requires root privileges!

Configure Jexus

When we use Jexus, one configuration file corresponds one website. If we have 3 websites, we need to create 3 configuration files!

Copy a default configuration file , and modify it.

  1. cp /usr/jexus/siteconfig/default /usr/jexus/siteconfig/myapp
  2. vim /usr/jexus/siteconfig/myapp

Here is an example configuration file for our application.

  1. ######################
  2. # Web Site: Default
  3. ########################################
  4. port=8080
  5. root=/ /var/www/myapp8080
  6. hosts=* #OR your.com,*.your.com
  7. # addr=0.0.0.0
  8. # CheckQuery=false
  9. # NoLog=true
  10. AppHost={
  11. cmd=dotnet /var/www/myapp8080/myapp.dll;
  12. root=/var/www/myapp8080;
  13. port=0
  14. }
  15. # NoFile=/index.aspx
  16. # Keep_Alive=false
  17. # UseGZIP=false
  18. # UseHttps=true
  19. # ssl.certificate=/x/xxx.crt #or pem
  20. # ssl.certificatekey=/x/xxx.key
  21. # ssl.protocol=TLSv1.0 # TLSv1.1 or TLSv1.2...
  22. # ssl.ciphers=
  23. # DenyFrom=192.168.0.233, 192.168.1.*, 192.168.2.0/24
  24. # AllowFrom=192.168.*.*
  25. # DenyDirs=~/cgi, ~/upfiles
  26. # indexes=myindex.aspx
  27. # rewrite=^/.+?\.(asp|php|cgi|pl|sh)$ /index.aspx
  28. # reproxy=/bbs/ http://192.168.1.112/bbs/
  29. # host.Redirect=abc.com www.abc.com 301
  30. # ResponseHandler.Add=myKey:myValue
  31. # Jexus php fastcgi address is '/var/run/jexus/phpsvr'
  32. #######################################################
  33. # fastcgi.add=php|socket:/var/run/jexus/phpsvr
  34. # php-fpm listen address is '127.0.0.1:9000'
  35. ############################################
  36. # fastcgi.add=php|tcp:127.0.0.1:9000

There are many configuration items in this file.

We need to modify 4 items!

  1. port : specify the port that you can visit.
  2. root : specify the path of your app.
  3. host : specify your domain.
  4. AppHost : specify some configuration for your ASP.NET Core project.

Based on the above example configuration file, we can learn that the app’s root path is /var/www/myapp8080 and we can visit http://ipaddress:8080 to access our app.

Note

You should not use UserUrls in your Program.cs, because of Port Negotiation, which is a feature of Jexus. This is also the reason why we set the port to 0 in AppHost's port node.

  1. public static IWebHost BuildWebHost(string[] args) =>
  2. WebHost.CreateDefaultBuilder(args)
  3. .UseStartup<Startup>()
  4. //Don't use UserUrls here!!!!
  5. //.UseUrls("http://*:9000")
  6. .Build();

Restart Jexus and use curl command to test this app.

ASP.NET Core

Open firewall port so that the Operating System will allow all TCP packets on destination port 8080.

  1. firewall-cmd --zone=public --add-port=8080/tcp --permanent
  2. firewall-cmd --reload

Now, we can visit our app on the browser.

ASP.NET Core

Only in a few steps, we have deployed our project to Linux. It is easier than Nginx.

We also can enable SSL easily when we use Jexus.

SSL configuration

Step 1

Use the following command to find out SSL lib .

  1. find / -name libssl.so.*

ASP.NET Core

Step 2

Create links between libssl.so.10 and libssl.so.

  1. cd /usr/jexus/runtime/lib/
  2. ls
  3. ln -sf /usr/lib64/libssl.so.10 libssl.so

ASP.NET Core

Note

libssl.so.10 will change based on your Operation System!! Maybe you need to do some change here.

Step 3

Edit your website's configuration.

  1. #The port must be 443 !!!
  2. port=443
  3. hosts=*
  4. UseHttps=true
  5. #your certificate file path
  6. ssl.certificate=/x/xxx.crt #or pem
  7. ssl.certificatekey=/x/xxx.key
  8. ssl.protocol=TLSv1.0 # TLSv1.1 or TLSv1.2

  1. Change the port from 8080 to 443
  2. Unlock comments of SSL
  3. replace path of your certificate file

Step 4

Restart Jexus Web Server

  1. sudo /usr/jexus/./jws restart
Step 5

Open a browser and test the website.

ASP.NET Core

Basic Operation of Jexus

  1. Start
  1. sudo /usr/jexus/./jws start

  1. Stop
  1. sudo /usr/jexus/./jws stop

  1. Restart
  1. sudo /usr/jexus/./jws restart

  1. Start or Restart a special website
  1. sudo /usr/jexus/./jws start myapp8080
  2. sudo /usr/jexus/./jws restart myapp8080

Summary

This article introduced a new and easier way to host your ASP.NET Core project. Hope this will help you!