Linux uses Jexus to host ASP. NET core applications

Source: Internet
Author: User
Tags dotnet fpm

First step to install the. Net Core Environment

Install dotnet Environment See the official website Https://www.microsoft.com/net/core.

Select the appropriate system version to install. After the installation is completed, enter the command to view the version, the latest version is 1.04:

Dotnet--version

At this point, you can already publish an ASP. NET core application running on Linux

Publish the ASP. NET core program to a Linux server and run it through the dotnet command, such as:

After successful running, it displays:

Hosting environment:productioncontent Root Path:/Application full path/nowlistening on:http://localhost:5000application Started. Press CTRL + C to shut down.

(An ASP. NET core application uses port 5000 by default, you can make custom ports in Project Program.cs, but do not recommend custom ports in Program.cs)

However, at this point, the ASP. NET core application ends when the current SSH session is closed.

So what should we do? Use Jexus! (Need to use 5.8.* version or later)

Jexus website Address: https://www.jexus.org/

Jexus website Forum: https://www.linuxdot.net

Step Two Install Jexus

Install Jexus Use the command directly (need to execute under root):

Curl https://jexus.org/release/x64/install.sh|sh

After successful installation, you will be prompted: OK, Jexus has been installed In/usr/jexus.

The third step is to publish the program to the Linux server

Publish the ASP. NET Core Application folder to the Linux server under the/var/www/path

(If the WWW folder does not exist, use the mkdir/var/www/ command to create the WWW folder)

At this point, the full path to the application is /var/www/application Folder/application name. dll

Fourth Step configuration Jexus running the ASP. NET Core Application

Use the following command:

1. Switch to jexus configuration file directory

Cd/usr/jexus/siteconf

2. Copy the default configuration file as test

default Test

3. Edit the test configuration file

VI Test

The default content of the test file is:

####################### Web site:default ####################################### #port= theRoot=/ /var/www/defaulthosts=* #OR your.com,*. your.com# addr=0.0.0.0# Checkquery=falseNoLog=true# AppHost={CMDLINE=/USR/LOCAL/X/XX; approot=/usr/local/x; port= the}# 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.1or TLSV1.2... # ssl.ciphers=# Denyfrom=192.168.0.233,192.168.1.*,192.168.2.0/ -# 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.com301# 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

When the edits are complete, the contents of test are (note that each item in the Apphost should have a semicolon at the end of the English half-width):

####################### Web site:test####################################### #port=8888Root=/ /var/www/Application Folder/hosts=* #OR your.com,*. your.com AppHost={cmd=dotnet application name: DLL; Root=/var/www/Application Folder/; Port=0;       }# Addr=0.0.0.0# Checkquery=falseNoLog=true# AppHost={CMDLINE=/USR/LOCAL/X/XX; approot=/usr/local/x; port= the}# 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.1or TLSV1.2... # ssl.ciphers=# Denyfrom=192.168.0.233,192.168.1.*,192.168.2.0/ -# 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.com301# 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

After editing, in the English half-width input method, press ESC to enter : Wq Finish saving the file modification and exit (the above changes will be described in detail below)

4. Start/Restart Jexus

Use the following command to start/restart Jexus when the profile editing is complete

/usr/jexus//usr/jexus/jws start

After a successful start/restart, enter the IP address/domain name in the browser: port number for example (192.168.1.1:8888 or www.aspnetcore.com:8888) to access the ASP. NET Core Application

These are the entire configuration process for the Jexus managed ASP. NET Core Application

With Microsoft's official introduction, the ASP. NET core application is running on the Kestrel server,

So what's the relationship between Jexus and Kestrel? Just like the relationship between Apache and Tomcat.

Jexus as a Web server, Kestrel is an application server, Jexus sends the request sent by the browser to Kestrel,kestrel to return the processing results to Jexus after the request is submitted to the ASP. Again by the Jexus response to the browser,:

We can see the process of a complete request response through the picture above.

So how does Jexus forward the request to the ASP. NET core application on the Kestrel server?

Here has to sigh jexus strength and ease of use, just need to simply edit the configuration file.

In the fourth step above, when you configure Jexus to run an ASP. test file, the content after editing means

 port=8888 # External access to the port number, can be changed to the port number you want, external access through the ip/domain name: port number to access root=//var/www/application Folder/ # application's working root directory (full path) hosts  =* #OR your.com,*.your.com # If set for server DNS resolution, you can fill in the domain name that resolves to the server, such as: Www.myweb.comAppHost  ={# The most important configuration cmd
    =dotnet application name. dll; # command to launch the command 
Root =/var/www/application folder to be executed by the ASP. Port = 0 for the ASP. NET core application; # The port number used by the ASP. NET core application, if the Usrurls custom port is used in the program, use the ports that are filled in usrurls (Usrurls custom ports are not recommended), and
# is not There is a case where using the Usrurls custom port is set to 0,jexus the port number that will be "negotiated" with ASP. NET core at run time, avoiding the hassle of multiple apps assigning # ports and the risk of conflict.

The point of configuration is to apphost that the port (port number) in Apphost does not represent the port (port number) of Jexus external service, but rather the port number of the ASP. In simple terms, an external request is forwarded to this port, and the request is processed by the ASP. NET Core application.

It is highly recommended to negotiate ports instead of using Usrurls in ASP . set up ports to avoid the hassle of assigning ports to multiple apps and the risk of conflict

Recommended Blog:

Blog of Woo Cloud

Zhang Shanyu's Technical Blog

Jinghong's Blog

Technical blog of the clothing Mingzhi

Another recommended blog:

Jexus boot up

Another thanks to woo convective Big Brother's patient guidance.

(Bowen writes the dish, asks the big guy Mo to abandon Orz ...)

Linux uses Jexus to host ASP. NET Core Applications

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.