.NET Core 是.NET Framework的新一代版本,是微软开发的第一个官方版本,具有跨平台 (Windows、Mac OSX、Linux) 能力的应用程序开发框架
(Application Framework)。

安装.Net Core执行代码

安装.Net Core

[root@localhost ~]# yum -y install libunwind libicu
[root@localhost ~]# curl -SL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?linkid=848821
[root@localhost ~]# mkdir /usr/local/dotnet
[root@localhost ~]# tar zxf dotnet.tar.gz -C /usr/local/dotnet
[root@localhost ~]# ln -s /usr/local/dotnet/dotnet /usr/local/bin/

创建 Hello World 控制台程序

# 创建hwapp项目
[root@localhost ~]# dotnet new console -o hwapp
...
The template "Console Application" created successfully.
# 运行项目
[root@localhost ~]# cd hwapp
[root@localhost hwapp]# dotnet restore
[root@localhost hwapp]# dotnet run
Hello World!

创建并运行 ASP.NET Core Web 应用

[root@localhost hwapp]# cd /home
[root@localhost home]# mkdir aspnetcoreapp
[root@localhost home]# cd aspnetcoreapp/
[root@localhost aspnetcoreapp]# dotnet new web
Content generation time: 282.8633 ms
The template "ASP.NET Core Empty" created successfully.
[root@localhost aspnetcoreapp]# dotnet restore
# 阻塞方式,启动成功ctrl-c打断即可
[root@localhost aspnetcoreapp]# dotnet run
Hosting environment: Production
Content root path: /home/aspnetcoreapp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

在本机访问http://localhost:5000

[root@localhost ~]# curl localhost:5000
Hello World!

安装Jexus

通常情况下,对外提供的 Web 服务都在 80或者443 端口,而我们的 Web 应用程序默认运行在5000端口,在 Windows 上可以使用 IIS 来宿主 ASP.NET Core,在 Linux 下可以用 Nginx,Apache,Jexus 等来作为宿主。这里以Jexus为例

安装独立版Jexus

[root@localhost ~]# curl https://jexus.org/release/x64/install.sh|sh
...
OK, Jexus has been installed in /usr/jexus.

独立版 Jexus 自带 Mono,使用的是Mono的稳定版本 4.8。

配置Jexus

将aspnetcoreapp部署到Jexus

[root@localhost ~]# cd /home/aspnetcoreapp/
[root@localhost aspnetcoreapp]# dotnet publish -o /var/www/aspnetcore/
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

  aspnetcoreapp -> /home/aspnetcoreapp/bin/Debug/netcoreapp1.1/aspnetcoreapp.dll

启动服务监听端口

# 阻塞,启动成功ctrl-c打断即可
[root@localhost aspnetcoreapp]# dotnet /var/www/aspnetcore/aspnetcoreapp.dll
Hosting environment: Production
Content root path: /home/aspnetcoreapp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

配置Jexus网站

创建aspnetcore配置文件

[root@localhost aspnetcoreapp]# cd /usr/jexus/siteconf/
[root@localhost siteconf]# cp default aspnetcore
[root@localhost siteconf]# vim aspnetcore 
root=/ /var/www/aspnetcore
# 添加
AppHost={
    cmd=dotnet /var/www/aspnetcore/aspnetcoreapp.dll;
    root=/var/www/aspnetcore;
    port=0;
}

配置的重点就在于AppHost,AppHost中的port不代表Jexus对外服务的端口号,而是指要转发的 Asp.Net Core 应用程序的端口号。不建议使用 UsrUrls 自定义端口,端口号设置为 0,Jexus 会在运行时与 Asp.Net Core 进行”协商”具体使用的端口号,避免端口冲突的风险。

启动Jexus

[root@localhost siteconf]# sh /usr/jexus/jws start
Restarting ... OK

验证

[root@localhost ~]# curl 192.168.1.1
Hello World!

评论




正在载入...
PoweredHexo
HostedAliyun
DNSAliyun
ThemeVolantis
UV
PV
BY-NC-SA 4.0