记IIS升级迁移之旅

场景

有一台Windows Server 2008机器,因为操作系统更新的原因,需要升级到 2022, 这台机器上原先部署了IIS 应用, 所以需要一并迁移。

  • 旧机器: Windows Server 2008 , IIS7 ,.NET 版本v4.0
  • 新机器: Windows Server 2022, IIS8
    记IIS升级迁移之旅_第1张图片

迁移步骤规划

迁移的步骤其实很简单:

  1. 在新机器上安装IIS
  2. 将项目目录从旧机器复制到新机器
  3. 建立Site, 指定项目目录, 并启动站点
    虽然过程看上去很简单,但是在实际的迁移过程中还是遇到了一些问题,接下来就详细介绍相关步骤及问题的解决。

Windows Server 2022下IIS的安装

Windows Server 2022 是微软推出的一款服务器操作系统。
Internet Information Services(IIS)是 Windows Server 内置的一款功能强大的 Web 服务器。IIS 可以托管各种类型的网站和 Web 应用程序,支持多种编程语言和技术,如 ASP.NET、C#、PHP、Python、Node.js 等。
要在 Windows Server 2022 上使用 IIS,需要首先安装和配置 IIS 角色。

以下是如何在 Windows Server 2022 上安装和配置 IIS 的步骤:

  1. 使用管理员权限登录 Windows Server 2022。

  2. 打开“服务器管理器”(Server Manager),点击“添加角色和功能”(Add roles and features)。

  3. 在“添加角色和功能向导”窗口中,选择“基于角色或基于功能的安装”(Role-based or feature-based installation),然后点击“下一步”(Next)。

  4. 在“服务器选择”(Server Selection)屏幕上,选择要在其上安装 IIS 的服务器,并点击“下一步”(Next)。

  5. 在“服务器角色”(Server Roles)屏幕上,勾选“Web 服务器(IIS)”(Web Server(IIS)),然后点击“添加功能”(Add Features)以添加所需的其他功能。

  6. 点击“下一步”(Next),然后在“功能”(Features)屏幕上根据您的需求添加其他功能,点击“下一步”(Next)。

  7. 在“Web 服务器角色(IIS)”(Web Server Role(IIS))屏幕上,点击“下一步”(Next)。

  8. 在“角色服务”(Role Services)屏幕上,勾选所需的 IIS 组件,例如“ASP.NET”,执行脚本支持,静态内容设置等。点击“下一步”(Next)。

确认所选的选项,然后点击“安装”(Install)以开始安装过程。

安装完成后,点击“完成”(Close)。

默认情况下,IIS 已经创建了一个名为 “Default Web Site” 的示例网站,它的物理路径通常位于 %SystemDrive%\inetpub\wwwroot。要查看 IIS 是否正常工作,可以在服务器的 Web 浏览器中输入 http://localhost,如果看到 IIS 的欢迎页面,说明 IIS 已成功安装并运行。

0x80070021 的问题及解决

0x80070021 错误通常出现在试图配置 HTTP 处理程序(handler)或模块(module)时,该错误可能与某个特定处理程序或模块的配置有关。

错误 0x80070021 可能表明已锁定某个配置文件部分,例如 handlers 或 modules,以阻止去配置它们。这通常是出于安全考虑的默认行为。

解决方案通常是打开 applicationHost.config 文件(位于 %windir%\system32\inetsrv\config\),然后找到 handlers 或 modules 部分,确认其 overrideModeDefault 属性是否设置为 Deny。如果是,则需要将其更改为 Allow。

注意: 改动之前,可以先备份 applicationHost.config 文件,然后再做出任何更改。

这是一个更改 handlers 部分以允许重写的例子:

更改之后,保存 applicationHost.config 文件,然后尝试重新启动 IIS 或相应的网站来查看错误是否已解决。

请注意,此改动可能会让IIS 应用更露于对攻击的风险,因此确定需要解锁及已对风险有所准备的情况下再进行上述更改。

Handler “ExtensionlessUrlHandler-Integrated-4.0” has a bad module “ManagedPipelineHandler” in its module list

该错误的完整错误信息及描述如下:


HTTP Error 500.21 - Internal Server Error
Handler "ExtensionlessUrlHandler-Integrated-4.0" has a bad module "ManagedPipelineHandler" in its module list

Most likely causes:
Managed handler is used; however, ASP.NET is not installed or is not installed completely.
There is a typographical error in the configuration for the handler module list.
During application initialization, either the application initialization feature has set skipManagedModules to true, or a rewrite rule is setting a URL that maps to a managed handler and is also setting SKIP_MANAGED_MODULES=1.

Things you can try:
Install ASP.NET if you are using managed handler.
Ensure that the handler module's name is specified correctly. Module names are case-sensitive and use the format modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule".
Ensure that any application initialization rewrite rules set SKIP_MANAGED_MODULE=0 when setting a URL that maps to a managed handler (such as .aspx, for example.)
As an alternative, ensure that application initialization rewrite rules map the request to an unmanaged handler (for example, to an .htm file, which is mapped to the StaticFileHandler.)


在2008 版本的时候也出现过这种问题, 可以通过安装.NET的方式进行解决,使用的命令如下:

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

但是在2022 中, 使用上述命令的时候出现如下的错误提示:

Microsoft (R) ASP.NET RegIIS version 4.0.30319.0
Administration utility to install and uninstall ASP.NET on the local machine.
Copyright (C) Microsoft Corporation.  All rights reserved.
Start installing ASP.NET (4.0.30319.0).
This option is not supported on this version of the operating system.  Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog,  the Server Manager management tool, or the dism.exe command line tool.  For more details please see http://go.microsoft.com/fwlink/?LinkID=216771.
Finished installing ASP.NET (4.0.30319.0).

这个错误提示的意思就是 4.0 版本太低了, 需要安装 4.5 版本。

于是回到Server Manger, 选中 以下部分进行安装

  • ASP.NET 4.8
  • .NET Extensibility 4.8

补充.NET的安装路径

在 Windows 系统中, .NET Framework 4.8 的默认安装路径如下:

对于 32 位 (x86) 系统,.NET Framework 4.8 对应的目录是:

Copy code

C:\Windows\Microsoft.NET\Framework\v4.0.30319
对于 64 位 (x64) 系统,.NET Framework 4.8 对应的目录是:

Copy code

C:\Windows\Microsoft.NET\Framework64\v4.0.30319
在这些目录下,可以找到 .NET 4.8 版本的许多运行库和工具,包括 aspnet_regiis.exe(ASP.NET IIS 注册工具)等。

另外,如果在 IIS 中托管了 ASP.NET 网站或应用程序,它们的默认安装路径(或者说部署路径)通常是 C:\inetpub\wwwroot\。不过,这个路径是可以在 IIS 中设置的,实际路径可能根据你的 IIS 配置而变化。

总的来说,.NET Framework 的安装路径和你的 ASP.NET 应用程序的部署路径是可以分开的,即使它们使用的是同一个 .NET Framework 版本。



你可能感兴趣的:(450-操作系统及相关,IIS8,.NET)