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
- Install .NET SDK on your server (Here I use CentOS 7.x).
- 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.
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
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.
- cp /usr/jexus/siteconfig/default /usr/jexus/siteconfig/myapp
-
- vim /usr/jexus/siteconfig/myapp
Here is an example configuration file for our application.
- ######################
- # Web Site: Default
- ########################################
-
- port=8080
- root=/ /var/www/myapp8080
- hosts=* #OR your.com,*.your.com
-
-
- # addr=0.0.0.0
- # CheckQuery=false
- # NoLog=true
- AppHost={
- cmd=dotnet /var/www/myapp8080/myapp.dll;
- root=/var/www/myapp8080;
- port=0
- }
- # NoFile=/index.aspx
- # Keep_Alive=false
- # UseGZIP=false
-
- # UseHttps=true
- # ssl.certificate=/x/xxx.crt #or pem
- # ssl.certificatekey=/x/xxx.key
- # ssl.protocol=TLSv1.0 # TLSv1.1 or TLSv1.2...
- # ssl.ciphers=
-
- # DenyFrom=192.168.0.233, 192.168.1.*, 192.168.2.0/24
- # AllowFrom=192.168.*.*
- # DenyDirs=~/cgi, ~/upfiles
- # indexes=myindex.aspx
- # rewrite=^/.+?\.(asp|php|cgi|pl|sh)$ /index.aspx
- # reproxy=/bbs/ http://192.168.1.112/bbs/
- # host.Redirect=abc.com www.abc.com 301
- # ResponseHandler.Add=myKey:myValue
-
-
- # Jexus php fastcgi address is '/var/run/jexus/phpsvr'
- #######################################################
- # fastcgi.add=php|socket:/var/run/jexus/phpsvr
-
- # php-fpm listen address is '127.0.0.1:9000'
- ############################################
- # fastcgi.add=php|tcp:127.0.0.1:9000
There are many configuration items in this file.
We need to modify 4 items!
- port : specify the port that you can visit.
- root : specify the path of your app.
- host : specify your domain.
- 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.
- public static IWebHost BuildWebHost(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup<Startup>()
-
-
- .Build();
Restart Jexus and use curl command to test this app.
Open firewall port so that the Operating System will allow all TCP packets on destination port 8080.
- firewall-cmd --zone=public --add-port=8080/tcp --permanent
-
- firewall-cmd --reload
Now, we can visit our app on the browser.
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 .
Step 2
Create links between libssl.so.10 and libssl.so.
- cd /usr/jexus/runtime/lib/
-
- ls
-
- ln -sf /usr/lib64/libssl.so.10 libssl.so
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.
- #The port must be 443 !!!
- port=443
- hosts=*
- UseHttps=true
- #your certificate file path
- ssl.certificate=/x/xxx.crt #or pem
- ssl.certificatekey=/x/xxx.key
- ssl.protocol=TLSv1.0 # TLSv1.1 or TLSv1.2
- Change the port from 8080 to 443
- Unlock comments of SSL
- replace path of your certificate file
Step 4
Restart Jexus Web Server
- sudo /usr/jexus/./jws restart
Step 5
Open a browser and test the website.
Basic Operation of Jexus
- Start
- sudo /usr/jexus/./jws start
- Stop
- sudo /usr/jexus/./jws stop
- Restart
- sudo /usr/jexus/./jws restart
- Start or Restart a special website
- sudo /usr/jexus/./jws start myapp8080
-
- 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!