Host ASP.NET Core On Linux With Jexus

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.   
  3. vim /usr/jexus/siteconfig/myapp  

Here is an example configuration file for our application.

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

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.   
  3. 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.   
  3. ls   
  4.   
  5. 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.   
  3. 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!

Up Next
    Ebook Download
    View all
    Learn
    View all