mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-23 11:51:09 +08:00
196 lines
6.4 KiB
Plaintext
196 lines
6.4 KiB
Plaintext
---
|
||
id: 402
|
||
title: IIS部署
|
||
---
|
||
|
||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||
import Tag from "@site/src/components/Tag.js";
|
||
import Highlight from '@site/src/components/Highlight.js';
|
||
|
||
:::caution 注意
|
||
|
||
1、必须启用IIS WebSocket协议
|
||
|
||
2、禁用IIS回收
|
||
:::
|
||
|
||
|
||
:::tip `提示`
|
||
|
||
如果需要Runtime依赖部署,需要安装ASP.NET Core Runtime,如果是独立发布部署,则不需要安装Runtime
|
||
|
||
下载链接:https://dotnet.microsoft.com/zh-cn/download/dotnet
|
||
|
||
:::
|
||
|
||
|
||
:::tip 精简发布文件
|
||
|
||
如果需要精简发布后的文件,也就是删除不必要的文件夹,可以编辑 Web 项目的 `.csproj` 并添加 `<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>`,如:
|
||
|
||
```cs showLineNumbers {3}
|
||
<PropertyGroup>
|
||
<TargetFramework>net6.0</TargetFramework>
|
||
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
|
||
</PropertyGroup>
|
||
```
|
||
|
||
若无需生成 `.pdb` 文件,可以继续添加:
|
||
|
||
```cs showLineNumbers {2-3}
|
||
<PropertyGroup>
|
||
<DebugType>none</DebugType>
|
||
<DebugSymbols>false</DebugSymbols>
|
||
</PropertyGroup>
|
||
```
|
||
|
||
:::
|
||
|
||
|
||
## 服务器环境配置
|
||
|
||
### 第一步
|
||
|
||
安装.NET Core 运行时捆绑包:[点击下载](https://dotnet.microsoft.com/permalink/dotnetcore-current-windows-runtime-bundle-installer)
|
||
|
||
### 第二步(命令)
|
||
|
||
```bash showLineNumbers
|
||
net stop was /y
|
||
```
|
||
|
||
### 第三步(命令)
|
||
|
||
```bash showLineNumbers
|
||
net start w3svc
|
||
```
|
||
|
||
### 第四步(命令)
|
||
|
||
```bash showLineNumbers
|
||
set ASPNETCORE_ENVIRONMENT=Production
|
||
```
|
||
|
||
## 部署到 IIS
|
||
|
||
### 添加新网站
|
||
|
||
<img src={require("@site/static/img/furion/ds1.png").default} />
|
||
|
||
### 配置网站信息
|
||
|
||
<img src={require("@site/static/img/furion/ds2.png").default} />
|
||
|
||
### 34.1.3.3 配置应用程序池
|
||
|
||
<img src={require("@site/static/img/furion/ds3.png").default} />
|
||
|
||
### 34.1.3.4 设置为 `非托管`
|
||
|
||
<img src={require("@site/static/img/furion/ds4.png").default} />
|
||
|
||
### 34.1.3.5 重启网站
|
||
|
||
只需重启网站或应用程序池即可。
|
||
|
||
## 34.1.4 常见问题
|
||
|
||
### 34.1.4.1 405 状态码,不支持 `PUT,DELETE` 请求
|
||
|
||
默认情况下,`IIS`拒绝 `PUT`和 `DELETE` 请求,原因为 `IIS` 默认注册了一个名为 `WebDAVModule` 的自定义 `HttpModule` 导致的。
|
||
|
||
解决该问题,只需要在 `web.config` 移除即可:
|
||
|
||
```xml {2-6}
|
||
<configuration>
|
||
<system.webServer>
|
||
<modules runAllManagedModulesForAllRequests="true">
|
||
<remove name="webDAVModule"/>
|
||
</modules>
|
||
</system.webServer>
|
||
</configuration>
|
||
```
|
||
|
||
微软官方文档:[https://docs.microsoft.com/zh-cn/troubleshoot/developer/webapps/iis/health-diagnostic-performance/http-error-405-website](https://docs.microsoft.com/zh-cn/troubleshoot/developer/webapps/iis/health-diagnostic-performance/http-error-405-website)
|
||
|
||
<img src={require("@site/static/img/furion/iis5.png").default} />
|
||
|
||
### 34.1.4.2 `WebSocket`/ `SignalR` 连接报错
|
||
|
||
如果项目部署在 `IIS` 中出现 `WebSoket`/`SignalR` 不能连接或连接失败等问题,请确保 `IIS` 服务中的 `WebSocket 协议` 是勾选状态
|
||
|
||
<img src={require("@site/static/img/furion/iis2.png").default} />
|
||
|
||
### 34.1.4.3 部署之后缺失 `api-ms-win.xxxx.dll` 问题
|
||
|
||
有时候将发布文件发布到服务器后,出现丢失 `api.ms-win.xxxx.dll` 文件,这时只需要重新发布并选择服务器特定的架构即可。
|
||
|
||
<img src={require("@site/static/img/furion/iis4.jpg").default} />
|
||
|
||
<img src={require("@site/static/img/furion/iis3.png").default} />
|
||
|
||
## 34.1.5 `IIS` 回收问题和配置
|
||
|
||
通过 `IIS` 部署 `.NET Core` 应用程序,如果启动了系统日志,就会发现经常出现 `Application is shutting down...` 的日志,代表 `IIS` 回收了应用程序池。
|
||
|
||
对于一个长期在线的网站来说,这是非常不合理的,所以我们可以通过以下配置让 `IIS` 进行长时间不访问便回收的机制。
|
||
|
||
---
|
||
|
||
配置步骤如下:
|
||
|
||
1. 打开 `IIS` 并点击左侧树根节点(计算机名称)并点击右侧的 `Configuration Editor`(配置编辑器)
|
||
|
||
<img src={require("@site/static/img/furion/iis6.png").default} />
|
||
|
||
2. 在 `Section`(节)选择 `system.applicationHost/applicationPools` 并设置 `startMode` 为 `AlwaysRunning`,之后点击 `Apply` 保存。
|
||
|
||
<img src={require("@site/static/img/furion/iis7.png").default} />
|
||
|
||
3. 点击左侧树根节点(计算机名称)下的 `Application Pools` 并点击最右侧的 `Set Appliation Pool Defaults...`(设置应用程序池默认配置...)
|
||
|
||
<img src={require("@site/static/img/furion/iis8.png").default} />
|
||
|
||
4. 设置 `Idle Time-out (minutes)`(闲置超时(分钟)为 `0`
|
||
|
||
<img src={require("@site/static/img/furion/iis9.png").default} />
|
||
|
||
这样即可解决 `IIS` 回收问题。
|
||
|
||
## 34.1.6 卷影(无占用)复制发布替换
|
||
|
||
正常情况下如果我们代码重新发布后替换 `IIS` 中的文件,这时候会出现文件占用无法进行替换,过去运维人员都是先停止站点后替换再启动。但我们也可以配置 `web.config` 文件启用卷影复制模式实现类似**热更新**操作,如:
|
||
|
||
```xml showLineNumbers {12-18}
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<configuration>
|
||
<!-- To customize the asp.net core module uncomment and edit the following section.
|
||
For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
|
||
|
||
<system.webServer>
|
||
<handlers>
|
||
<remove name="aspNetCore"/>
|
||
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModulev2" resourceType="Unspecified"/>
|
||
</handlers>
|
||
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
|
||
<handlerSettings>
|
||
<handlerSetting name="experimentalEnableShadowCopy" value="true" />
|
||
<handlerSetting name="shadowCopyDirectory" value="../ShadowCopyDirectory/" />
|
||
<!-- Only enable handler logging if you encounter issues-->
|
||
<!--<handlerSetting name="debugFile" value=".\logs\aspnetcore-debug.log" />-->
|
||
<!--<handlerSetting name="debugLevel" value="FILE,TRACE" />-->
|
||
</handlerSettings>
|
||
</aspNetCore>
|
||
</system.webServer>
|
||
</configuration>
|
||
```
|
||
|
||
关于卷影复制更多知识可查看以下文档:
|
||
|
||
- [https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-6-preview-3/#shadow-copying-in-iis](https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-net-6-preview-3/#shadow-copying-in-iis)
|
||
- [https://learn.microsoft.com/zh-cn/dotnet/framework/app-domains/shadow-copy-assemblies](https://learn.microsoft.com/zh-cn/dotnet/framework/app-domains/shadow-copy-assemblies)
|
||
|
||
|
||
|
||
|