fairyguo 发表于 2018-12-8 09:08:56

Windows Nano Server安装配置详解08:配置IIS

  安装 IIS 角色时默认启用大量的 IIS 功能(请参阅本主题的“Nano Server 上的 IIS 概述”部分中的表)。 可以使用 DISM.exe 启用(或禁用)其他功能。
  注意IIS功能的安装和配置是通过远程powershell连接到Nano Server进行的,如果没有配置远程powershell,可以参考我之前的文章:
  Windows Nano Server安装配置详解03:远程管理Nano Server - 曾垂鑫的技术专栏 - 运维网技术博客
  http://543925535.blog.运维网.com/639838/1862572
  Windows Nano Server安装配置详解02:初始化配置 - 曾垂鑫的技术专栏 - 运维网技术博客 http://543925535.blog.运维网.com/639838/1862322
1)安装或删除IIS的功能
  IIS 子功能列表
  IIS-WebServer
  IIS-CommonHttpFeatures
  IIS-StaticContent
  IIS-DefaultDocument
  IIS-DirectoryBrowsing
  IIS-HttpErrors
  IIS-HttpRedirect
  IIS-ApplicationDevelopment
  IIS-CGI
  IIS-ISAPIExtensions
  IIS-ISAPIFilter
  IIS-ServerSideIncludes
  IIS-WebSockets
  IIS-ApplicationInit
  IIS-Security
  IIS-BasicAuthentication
  IIS-WindowsAuthentication
  IIS-DigestAuthentication
  IIS-ClientCertificateMappingAuthentication
  IIS-IISCertificateMappingAuthentication
  IIS-URLAuthorization
  IIS-RequestFiltering
  IIS-IPSecurity
  IIS-CertProvider
  IIS-Performance
  IIS-HttpCompressionStatic
  IIS-HttpCompressionDynamic
  IIS-HealthAndDiagnostics
  IIS-HttpLogging
  IIS-LoggingLibraries
  IIS-RequestMonitor
  IIS-HttpTracing
  IIS-CustomLogging
  示例:安装 Windows 身份验证
  1.在 Nano Server上打开 Windows PowerShell 远程会话控制台。
  2.使用 DISM.exe 安装 Windows 身份验证模块:
  dism /Enable-Feature /online /featurename:IIS-WindowsAuthentication /all
http://s3.运维网.com/wyfs02/M01/8C/77/wKioL1htw5rhlXKMAADZHx666jc820.png
  /all 将安装选定的功能所依赖的任何功能。
  示例:卸载 Windows 身份验证
  1.在 Nano Server上打开 Windows PowerShell 远程会话控制台。
  2.使用 DISM.exe 卸载 Windows 身份验证模块:
  dism /Disable-Feature /online /featurename:IIS-WindowsAuthentication
http://s3.运维网.com/wyfs02/M02/8C/77/wKioL1htw5vj8fIYAAE3IcmczF8985.png
2)创建IIS站点
  New-IISSite -Name TestSite -BindingInformation "*:80:TestSite" -PhysicalPath c:\test
  先导入IIS的管理模块,再创建站点存放的目录,然后执行命令创建站点。
http://s3.运维网.com/wyfs02/M02/8C/77/wKioL1htw52ilFeXAAG8w9nssnc013.png
  查看创建的站点
http://s3.运维网.com/wyfs02/M00/8C/7A/wKiom1htw56RnQglAADeSOLlLQk748.png
  删除站点
http://s3.运维网.com/wyfs02/M01/8C/7A/wKiom1htw5_DlrKNAADIQ8bxJ48051.png
3)创建虚拟目录
  可以通过使用 Get-IISServerManager 返回的 IISServerManager 对象来创建虚拟目录,该对象公开了 NET Microsoft.Web.Administration.ServerManager API。 在此示例中,这些命令访问站点集合的“Default Web Site”元素和应用程序部分的根应用程序元素 ("/")。 然后这些命令为该应用程序元素调用 VirtualDirectories 集合的 Add() 方法,以便创建新目录:
http://s3.运维网.com/wyfs02/M02/8C/7A/wKiom1htw6DiaOzzAAG-GzuM6nQ412.png
  $sm = Get-IISServerManager
  $sm.Sites["Default Web Site"].Applications["/"].VirtualDirectories.Add("/DemoVirtualDir1", "c:\test\virtualDirectory1")
  $sm.Sites["Default Web Site"].Applications["/"].VirtualDirectories.Add("/DemoVirtualDir2", "c:\test\virtualDirectory2")
  $sm.CommitChanges()
http://s3.运维网.com/wyfs02/M00/8C/7A/wKiom1htw6Pg7D69AAJEzDBciqA499.png
  查看创建好的虚拟目录
http://s3.运维网.com/wyfs02/M00/8C/77/wKioL1htw6ajMBC6AAGqTOvGt0k942.png
4)创建应用程序池
  同样可以使用 Get-IISServerManager 创建应用程序池:
  $sm = Get-IISServerManager
  $sm.ApplicationPools.Add("DemoAppPool")
http://s3.运维网.com/wyfs02/M01/8C/7A/wKiom1htw6aSNctGAADmZRovPq8213.png
  查看创建好的应用程序池
http://s3.运维网.com/wyfs02/M02/8C/7A/wKiom1htw6eSNI4tAADSI655E_E256.png
5)配置 HTTPS 和证书
  使用 Certoc.exe 实用程序导入证书,如本示例中所示,其中显示了在 Nano Server 上为网站配置 HTTPS:
  1.在另一台没有运行 Nano Server 的计算机上,创建证书(使用自己的证书名称和密码),然后再将其导出到 c:\test.pfx。
  $newCert = New-SelfSignedCertificate -DnsName "www.demo.com" -CertStoreLocation cert:\LocalMachine\my
  $mypwd = ConvertTo-SecureString -String "abc@123" -Force -AsPlainText
  Export-PfxCertificate -FilePath c:\test.pfx -Cert $newCert -Password $mypwd
http://s3.运维网.com/wyfs02/M02/8C/7A/wKiom1htw6nA7AuxAAGOplV3XpE053.png
  2.将 test.pfx 文件复制到 Nano Server 计算机上。
http://s3.运维网.com/wyfs02/M01/8C/7A/wKiom1htw67hvYrvAAFLyIKKqNk770.png
  3.在 Nano Server上,使用以下命令将证书导入到“My”存储区:
  certoc.exe -ImportPFX -p abc@123 My c:\test.pfx
http://s3.运维网.com/wyfs02/M00/8C/7A/wKiom1htw7Cx6zBsAAHIPGoDFfs187.png
  4.使用 Get-ChildItem Cert:\LocalMachine\my 检索此新证书的指纹。
http://s3.运维网.com/wyfs02/M01/8C/7A/wKiom1htw7HxiSa4AADB9SEcIGg945.png
  5.通过使用以下 Windows PowerShell 命令将 HTTPS 绑定添加到默认网站(或想要添加绑定的任何网站):
  $certificate = get-item Cert:\LocalMachine\my\12F96C8065C4E43C4293AA0FDB94511F548F4B6C
  # Use your actual thumbprint instead of this example 证书指纹和上面获取到的保持一致
  $hash = $certificate.GetCertHash()
  Import-Module IISAdministration
  $sm = Get-IISServerManager
  $sm.Sites["Default Web Site"].Bindings.Add("*:443:", $hash, "My", "0") # My is the certificate store name
  $sm.CommitChanges()
http://s3.运维网.com/wyfs02/M01/8C/7A/wKiom1htw7LD7_paAAHsT_c69oM318.png
  还可以使用此语法结合使用服务器名称指示 (SNI) 和特定主机名称: $sm.Sites["Default Web Site"].Bindings.Add("*:443:www.demo.com", $hash, "My", "Sni".
  完成后,如图。
http://s3.运维网.com/wyfs02/M02/8C/7A/wKiom1htw7OieGUQAACd2YkMq0w020.png
  访问一下看看。
http://s3.运维网.com/wyfs02/M02/8C/77/wKioL1htw7XBUvXpAAFr0ggp7nk936.png
  官方参考文档:
  Nano Server 上的 IIS https://technet.microsoft.com/windows-server-docs/get-started/iis-on-nano-server
  欢迎扫描关注本人的微信公众号,获取更多IT资讯:
  http://s1.运维网.com/images/20180106/1515219089129007.jpg



页: [1]
查看完整版本: Windows Nano Server安装配置详解08:配置IIS