Microsoft IIS

Microsoft製のWindows専用Webサーバー。Windows環境との深い統合と.NETアプリケーションサポートが特徴。モジュラーアーキテクチャとASP.NET完全統合。

WebサーバーWindows.NETASP.NETMicrosoftエンタープライズ

Webサーバー

Microsoft IIS

概要

Microsoft Internet Information Services(IIS)は、Microsoft製のWindows専用Webサーバーです。Windows環境との深い統合と.NETアプリケーションの完全サポートが特徴で、エンタープライズ環境での安定した採用実績があります。Windows Server OSに標準搭載され、Microsoft技術スタックとのシームレスな連携により、企業システムでの信頼性の高いWebサービス提供を実現します。

詳細

IISは1995年にWindows NT 3.51向けにリリースされ、現在のバージョン10.0まで継続的に開発されています。現在のWebサーバー市場では5-10%のシェアを維持し、特にWindows環境やMicrosoft技術スタック採用企業での利用が継続されています。

主要な技術的特徴

  • Windows OS統合: Active DirectoryやWindows認証との完全連携
  • .NET フレームワーク対応: ASP.NET、ASP.NET Coreの最適実行環境
  • 管理ツール充実: IIS Manager によるGUI管理
  • セキュリティ機能: Windows セキュリティモデルとの統合
  • スケーラビリティ: Application Request Routing(ARR)によるロードバランシング

用途

  • ASP.NET/.NET Core Webアプリケーション
  • Windows環境でのWebサイトホスティング
  • 企業イントラネットシステム
  • SharePoint、Exchange等のMicrosoft製品基盤
  • ハイブリッドクラウド環境でのオンプレミス部分

メリット・デメリット

メリット

  • Windows統合: OSレベルでの最適化と深い統合
  • .NET最適化: ASP.NETアプリケーションの最高性能
  • 管理の簡単さ: GUIベースの直感的な管理インターフェース
  • 企業サポート: Microsoftによる包括的なサポート体制
  • セキュリティ: Windows セキュリティとの完全連携
  • Azure統合: クラウドとのハイブリッド展開が容易

デメリット

  • Windows専用: Linux等の他OSでは利用不可
  • ライセンスコスト: Windows Server ライセンスが必要
  • メモリ使用量: 比較的高いリソース消費
  • 柔軟性の制限: Windows環境に制約される
  • オープンソースコミュニティ: 限定的なコミュニティサポート

参考ページ

書き方の例

web.config基本設定

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <!-- デフォルトドキュメント設定 -->
    <defaultDocument>
      <files>
        <clear />
        <add value="Default.aspx" />
        <add value="index.html" />
        <add value="index.htm" />
      </files>
    </defaultDocument>
    
    <!-- MIME タイプ設定 -->
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".woff" mimeType="font/woff" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    </staticContent>
    
    <!-- 圧縮設定 -->
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
      </dynamicTypes>
    </httpCompression>
  </system.webServer>
</configuration>

URL Rewrite設定

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <!-- HTTPS リダイレクト -->
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
                  redirectType="Permanent" appendQueryString="false" />
        </rule>
        
        <!-- Pretty URL -->
        <rule name="Pretty URLs" stopProcessing="true">
          <match url="^([^/]+)/?$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="page.aspx?id={R:1}" />
        </rule>
        
        <!-- API ルーティング -->
        <rule name="API Routes" stopProcessing="true">
          <match url="^api/([^/]+)/([^/]+)/?$" />
          <action type="Rewrite" url="api/handler.ashx?controller={R:1}&amp;action={R:2}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

ASP.NET Core アプリケーション設定

<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet"
                  arguments=".\MyApp.dll"
                  stdoutLogEnabled="false"
                  stdoutLogFile=".\logs\stdout"
                  hostingModel="InProcess" />
    </system.webServer>
  </location>
</configuration>

セキュリティ設定

<configuration>
  <system.webServer>
    <!-- セキュリティヘッダー -->
    <httpProtocol>
      <customHeaders>
        <add name="X-Frame-Options" value="SAMEORIGIN" />
        <add name="X-Content-Type-Options" value="nosniff" />
        <add name="X-XSS-Protection" value="1; mode=block" />
        <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
        <add name="Content-Security-Policy" value="default-src 'self'" />
      </customHeaders>
    </httpProtocol>
    
    <!-- IP制限 -->
    <security>
      <ipSecurity>
        <add ipAddress="192.168.1.0" subnetMask="255.255.255.0" allowed="true" />
        <add ipAddress="10.0.0.0" subnetMask="255.0.0.0" allowed="true" />
        <add ipAddress="0.0.0.0" subnetMask="0.0.0.0" allowed="false" />
      </ipSecurity>
    </security>
    
    <!-- 認証設定 -->
    <security>
      <authentication>
        <windowsAuthentication enabled="true" />
        <anonymousAuthentication enabled="false" />
      </authentication>
    </security>
  </system.webServer>
</configuration>

PowerShell管理スクリプト

# IIS管理用PowerShellスクリプト

# WebAdministration モジュールをインポート
Import-Module WebAdministration

# 新しいサイト作成
New-Website -Name "ExampleSite" -Port 80 -PhysicalPath "C:\inetpub\wwwroot\example" -BindingInformation "*:80:example.com"

# SSL証明書バインド
New-WebBinding -Name "ExampleSite" -IP "*" -Port 443 -Protocol https
$cert = Get-ChildItem cert:\LocalMachine\My | Where-Object {$_.Subject -like "*example.com*"}
New-Item -Path IIS:\SslBindings\0.0.0.0!443 -Value $cert

# アプリケーションプール設定
New-WebAppPool -Name "ExampleAppPool"
Set-ItemProperty -Path "IIS:\AppPools\ExampleAppPool" -Name processModel.identityType -Value ApplicationPoolIdentity
Set-ItemProperty -Path "IIS:\AppPools\ExampleAppPool" -Name recycling.periodicRestart.time -Value "00:00:00"

# サイトにアプリケーションプール割り当て
Set-ItemProperty -Path "IIS:\Sites\ExampleSite" -Name applicationPool -Value "ExampleAppPool"

# ログ設定
Set-ItemProperty -Path "IIS:\Sites\ExampleSite" -Name logFile.logFormat -Value "W3C"
Set-ItemProperty -Path "IIS:\Sites\ExampleSite" -Name logFile.directory -Value "C:\inetpub\logs\LogFiles"

Application Request Routing (ARR)設定

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Load Balance Rule" patternSyntax="ECMAScript" stopProcessing="true">
          <match url=".*" />
          <action type="Rewrite" url="http://backend-farm/{R:0}" />
        </rule>
      </rules>
    </rewrite>
    
    <!-- ARR設定 -->
    <proxy enabled="true" />
    <applicationRequestRouting>
      <serverFarms>
        <serverFarm name="backend-farm">
          <server address="192.168.1.10" enabled="true" />
          <server address="192.168.1.11" enabled="true" />
          <server address="192.168.1.12" enabled="true" />
          <loadBalancing algorithm="RoundRobin" />
          <healthCheck enabled="true" interval="00:00:30" />
        </serverFarm>
      </serverFarms>
    </applicationRequestRouting>
  </system.webServer>
</configuration>

診断・ログ設定

<configuration>
  <system.webServer>
    <!-- カスタムエラーページ -->
    <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" path="/errors/404.html" responseMode="ExecuteURL" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="500" path="/errors/500.html" responseMode="ExecuteURL" />
    </httpErrors>
    
    <!-- トレース設定 -->
    <tracing>
      <traceFailedRequests>
        <add path="*.aspx">
          <traceAreas>
            <add provider="ASP" verbosity="Verbose" />
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
            <add provider="ISAPI Extension" verbosity="Verbose" />
            <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
          </traceAreas>
          <failureDefinitions statusCodes="500" timeTaken="00:00:30" />
        </add>
      </traceFailedRequests>
    </tracing>
  </system.webServer>
</configuration>