asp.net core hosting services to the windows, and do a reverse proxy configuration iis IIS to do a reverse proxy

Use NSSM to deploy to Windows .Net Core Services

 

Why deploy to Windows Services

In many cases, few would .Net Core project to deploy Windows service, especially Asp.net Core even less. Under normal circumstances, Asp.net Core will be deployed to the linux server or deploy to Windows, IIS. But we do not have to deploy Asp.net Core services in the case of Windows, such as Windows Server did not install IIS, or Core Asp.net some regular tasks, you need to run real-time, and so in some cases. 

 

Microsoft Solutions

Microsoft also provides a .Net Core deploying solutions to the Windows service, it should be said that Asp.net Core solution. Can be found in the official documentation  https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1&tabs=aspnetcore2x . But the official solution more complicated, but also need to change the part of the code.

 

What is NSSM?

Official website http://www.nssm.cc/ , Download http://www.nssm.cc/download

NSSM simple point to understand is that you can put some exe program packaged as a Windows service, and then run the exe program like service. And NSSM powerful, run more simple interface fool of treatment.

 

Use NSSM

Back to Asp.net Core 2.1 code shows as a demonstration, in line with other .Net Core ways.

1. Make sure .Net Core program works

First Asp.net Core release, and then run commands directly dotnet, ensure that the program can run and access

 

2, using the installation dotnet NSSM

Download NSSM, use the command window to NSSM directory to find nssm.exe directory is located, and then run NSSM install , and then will play box, select the files and folders.

Path: dotnet directory is located, usually the default is C: \ Program Files \ dotnet \ dotnet.exe;

Startup directory: the directory where the program is the last program directory where the dll;

Arguments: dll name of the program, usually the project name plus .dll;

Service name: The name to write on the service.

Then click on the Install service button to complete the deployment.

Finally, the Windows Service Manager interface to find the name of the service is installed, you can start right, so that you can very simply put .Net Core Managed Services to Window. Easy to manage, start, stop, and so on.

Reprinted from above:

Author: Emrys 
Source: http://www.cnblogs.com/emrys5/ 

Configure IIS to do a reverse proxy

 

Request Routing download and install the Application:  https://www.iis.net/downloads/microsoft/application-request-routing

1, the installation is successful re-open the console iis, iis on the panel will be more of ARR and URL rewriting component icons:
 
 
2. Click the root node in the left IIS find a red circle in the image above is the first double-click the icon to open, and then click Proxy below the right side of the Server Proxy Settings.

 

3, where the red circle directly check the map up and down, others do not control

 

 

 

 

 

4, a new site in IIS --TestWeb

 

5、点击IIS左边菜单中新建的站点TestWeb,在右边功能视图中双击"URL重写"模块打开。

 

6、点击右上边操作栏中的“添加规则”,弹出如下图的弹框,然后双击弹框中的“反向代理”。

 

7、然后将要转发的域名或者ip地址填入进去,然后点击确定,现在访问TestWeb的地址即可发现以转发到刚填入的地址中了

 

 

 

 

为什么部署至Windows Services

在很多情况下,很少会把.Net Core项目部署至Windows服务中,特别是Asp.net Core就更少了。一般情况下,Asp.net Core会部署至linux服务器,或者部署至Windows的IIS中。但也不排除会有Asp.net Core部署至Windows 服务中的情况,比如Windows服务器并没有安装IIS,或者Asp.net Core中存在一些定时任务,需要实时运行,等等一些情况。 

 

微软解决方案

微软也提供了.Net Core部署至Windows 服务的解决方案,应该说是Asp.net Core的解决方案。可以参看官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1&tabs=aspnetcore2x。但是官方的解决方案比较繁琐,而且需要更改部分代码。

 

什么是NSSM?

官网http://www.nssm.cc/,下载地址http://www.nssm.cc/download

简单点理解就是NSSM可以把一些exe程序封装成Windows服务,然后exe程序就像服务一样运行。而且NSSM功能强大,运行更简单,界面化傻瓜化处理方式。

 

使用NSSM

后面的代码演示以Asp.net Core 2.1作为演示,其他.Net Core方式一致。

1、确保.Net Core程序可以正常运行

先把Asp.net Core发布,然后直接运行dotnet命令,确保程序可以运行并访问

 

2、使用NSSM安装dotnet

下载NSSM,使用命令窗口至NSSM目录中找到nssm.exe所在的目录,然后运行nssm install,然后会弹框,选择相应的文件和文件夹。

Path:dotnet所在的目录,一般默认是在C:\Program Files\dotnet\dotnet.exe;

Startup directory:程序所在的目录,就是最后程序dll所在的目录;

Arguments:程序dll的名称,一般是项目名加上.dll;

Service name:在此写上服务的名称即可。

然后点击Install service按钮就完成了部署。

最后到Windows服务管理界面找到安装的服务名称,右键启动即可,这样就可以非常简单的把.Net Core托管至Window服务中。方便管理、启动、停止等等。

以上转载自:

作者:Emrys 
出处:http://www.cnblogs.com/emrys5/ 

配置IIS做反向代理

 

下载安装Application Request Routing: https://www.iis.net/downloads/microsoft/application-request-routing

1、安装成功后重新打开iis控制台,在iis面板上会多出URL重写和ARR组件图标:
 
 
2、在IIS左边点击根节点找到上图中的 第一个红圈中图标双击打开,然后点击右边的Proxy 下面的  Server Proxy Settings.

 

3、直接勾选上下图的红圈的地方,其他不用管

 

 

 

 

 

4、在IIS中新建站点--TestWeb

 

5、点击IIS左边菜单中新建的站点TestWeb,在右边功能视图中双击"URL重写"模块打开。

 

6、点击右上边操作栏中的“添加规则”,弹出如下图的弹框,然后双击弹框中的“反向代理”。

 

7、然后将要转发的域名或者ip地址填入进去,然后点击确定,现在访问TestWeb的地址即可发现以转发到刚填入的地址中了

 

 

 

 

Guess you like

Origin www.cnblogs.com/lkd3063601/p/11459509.html