2 분 소요

IIS(Internet Information Services)는 Windows Server에 내장된 웹 서버로, 기본 설정만으로도 사용 가능하지만 몇 가지 핵심 설정을 최적화하면 성능과 안정성을 크게 향상시킬 수 있습니다.

서버 터미널 이미지

최적화된 IIS 웹서버가 실행되는 Windows Server

애플리케이션 풀 최적화

애플리케이션 풀은 IIS 성능의 핵심입니다.

워커 프로세스 설정

# PowerShell로 앱 풀 설정
Import-Module WebAdministration

# 최대 워커 프로세스 수 (Web Garden)
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" `
  -Name processModel.maxProcesses -Value 4

# 아이들 타임아웃 설정 (분)
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" `
  -Name processModel.idleTimeout -Value "00:20:00"

# 정기 재활용 시간 설정 (새벽 3시)
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" `
  -Name recycling.periodicRestart.schedule `
  -Value @{value="03:00:00"}

# 메모리 한계로 재활용 (MB 단위, 0은 무제한)
Set-ItemProperty "IIS:\AppPools\DefaultAppPool" `
  -Name recycling.periodicRestart.privateMemory -Value 1048576  # 1GB

32비트 앱 활성화

# 32비트 레거시 앱 지원
Set-ItemProperty "IIS:\AppPools\LegacyPool" `
  -Name enable32BitAppOnWin64 -Value $true

정적 콘텐츠 압축

# 정적 파일 압축 활성화
Set-WebConfigurationProperty -Filter system.webServer/httpCompression `
  -Name staticCompressionEnabled -Value $true

Set-WebConfigurationProperty -Filter system.webServer/httpCompression `
  -Name dynamicCompressionEnabled -Value $true

# web.config에서 설정
# <system.webServer>
#   <httpCompression>
#     <staticTypes>
#       <add mimeType="text/*" enabled="true"/>
#       <add mimeType="application/javascript" enabled="true"/>
#       <add mimeType="application/json" enabled="true"/>
#     </staticTypes>
#   </httpCompression>
# </system.webServer>

정적 파일 캐싱

<!-- web.config -->
<system.webServer>
  <staticContent>
    <clientCache cacheControlMode="UseMaxAge"
                 cacheControlMaxAge="7.00:00:00" />
  </staticContent>

  <!-- MIME 타입 추가 (필요 시) -->
  <staticContent>
    <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    <mimeMap fileExtension=".webp" mimeType="image/webp" />
  </staticContent>
</system.webServer>

요청 필터링으로 보안 강화

# 최대 요청 크기 제한 (바이트)
Set-WebConfigurationProperty `
  -Filter system.webServer/security/requestFiltering/requestLimits `
  -Name maxAllowedContentLength `
  -Value 30000000  # 30MB

# URL 길이 제한
Set-WebConfigurationProperty `
  -Filter system.webServer/security/requestFiltering/requestLimits `
  -Name maxUrl -Value 4096

# 특정 파일 확장자 차단
Add-WebConfigurationProperty `
  -Filter system.webServer/security/requestFiltering/fileExtensions `
  -Name "." -Value @{fileExtension=".config"; allowed=$false}

모니터 화면 이미지

IIS 관리자에서 성능 설정을 조정하는 화면

연결 제한 및 타임아웃

# 연결 타임아웃 설정 (초)
Set-ItemProperty "IIS:\Sites\Default Web Site" `
  -Name limits.connectionTimeout -Value 120

# 최대 동시 연결 수
Set-ItemProperty "IIS:\Sites\Default Web Site" `
  -Name limits.maxConnections -Value 4294967295  # 무제한

# Keep-Alive 설정
Set-ItemProperty "IIS:\Sites\Default Web Site" `
  -Name httpProtocol.allowKeepAlive -Value $true

HTTP/2 활성화

# HTTP/2는 Windows Server 2016 이상에서 지원
# HTTPS 바인딩이 있어야 자동 활성화됨

# HTTP/2 지원 확인
netsh http show servicestate

# IIS에서 HTTP/2 비활성화 (문제 발생 시)
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\HTTP\Parameters" `
  -Name EnableHttp2Tls -Value 0

로그 설정 최적화

# 로그 형식을 W3C로 설정
Set-WebConfigurationProperty `
  -Filter system.applicationHost/sites/site[@name='Default Web Site']/logFile `
  -Name logFormat -Value W3C

# 로그 저장 경로 변경
Set-WebConfigurationProperty `
  -Filter system.applicationHost/sites/site[@name='Default Web Site']/logFile `
  -Name directory -Value "D:\IISLogs"

# 오래된 로그 자동 삭제 (PowerShell 스케줄)
Get-ChildItem "D:\IISLogs" -Recurse -File |
  Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } |
  Remove-Item -Force

성능 카운터 모니터링

# 실시간 IIS 성능 카운터 확인
Get-Counter -Counter "\Web Service(_Total)\Current Connections"
Get-Counter -Counter "\Web Service(_Total)\Bytes Received/sec"
Get-Counter -Counter "\Web Service(_Total)\Requests/sec"

# 지속 모니터링 (5초 간격)
Get-Counter -Counter @(
    "\Web Service(_Total)\Current Connections",
    "\Web Service(_Total)\Requests/sec"
) -SampleInterval 5 -MaxSamples 60

IIS 성능 최적화는 애플리케이션 풀 설정, 압축, 캐싱의 3가지를 우선적으로 적용하면 체감 성능이 크게 개선됩니다. 변경 후 반드시 이벤트 뷰어와 성능 카운터로 영향을 모니터링하세요.

댓글남기기