2012-12-10 11 views
5

これは何時間も読んでいます。数十のSOの投稿やブログなどが見つかりません。Json HTTP圧縮でIIS8でGzipを使用する

目標:WCFサービスからのjson応答の動的なhttp圧縮を有効にします。 applicationHost.configから欠落している残念ながら、サーバー上の

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> 
      <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> 
     <dynamicTypes> 
      <add mimeType="text/*" enabled="true" /> 
      <add mimeType="message/*" enabled="true" /> 
      <add mimeType="application/x-javascript" enabled="true" /> 
      <add mimeType="application/json; charset=utf-8" enabled="true" /> 
      <add mimeType="*/*" enabled="false" /> 
     </dynamicTypes> 
     <staticTypes> 
      <add mimeType="text/*" enabled="true" /> 
      <add mimeType="message/*" enabled="true" /> 
      <add mimeType="application/x-javascript" enabled="true" /> 
      <add mimeType="application/atom+xml" enabled="true" /> 
      <add mimeType="application/xaml+xml" enabled="true" /> 
      <add mimeType="*/*" enabled="false" /> 
     </staticTypes>  
</httpCompression> 
</system.webServer> 

私は次の行を使用しています:

注:applicationHost.configのには、次の含まれている場合にgzipは既に静的コンテンツ用のコンテンツと動的コンテンツのために働く

<add mimeType="application/json; charset=utf-8" enabled="true" /> 

とサーバがElastic Beanstalkで(彼らが起動されるたびに、このようなとして私は1つのインスタンスではなく、すべてのインスタンスでそれを変更することができます)が立ち上げたAWS EC2インスタンスであるので、私はそれを手動で追加することはできません。

<section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" /> 

私は私のアプリのweb.configでhttpCompressionセクションをオーバーライドすることはできませんことを意味します

はまた、残念ながら、applicationHost.configのは、この行が含まれています。

私の質問:動的コンテンツのgzip圧縮を有効にする他の方法がありますか?

overrideModeDefault = "Allow"の場合、httpCompressionセクションをアプリケーションのweb.configに配置してオーバーライドすることができますか?

必要に応じてさらに詳しい説明を追加してください。

乾杯、ここでパーティに後期

+0

この同じ問題の解決策も探しています。 –

+0

重複... http://stackoverflow.com/questions/4584956/compressing-a-web-service-response-for-jquery http://stackoverflow.com/questions/10795165/iis-7-5 -not-compressing-json-when-application-web-configに設定する – ncubica

+0

あなたの問題をどのように解決するのですか? – ncubica

答えて

0

が、これはAMIずに間違いなく可能です。

セットアップファイルをホストするs3バケットを作成します。この例では、私はmys3bucketと呼ばれるバケットを持っています。次のファイルをmybucket/ebExtensions/setup.ps1の下にあるバケットにアップロードします。

このファイルは、ルートアプリケーションのホスト設定を変更しました。

write-host "Applying IIS configuration ..." 

$globalConfig = "C:\Windows\System32\inetsrv\config\applicationHost.config" 

$xmlDoc = new-object System.Xml.XmlDocument 

$xmlDoc.Load($globalConfig) 

#Set minimum compression size 
write-host "Setting minimum compression size ..." 
$xmlCurrentNode = $xmlDoc.SelectSingleNode("/configuration/system.webServer/httpCompression") 
if ($xmlCurrentNode -eq $null) 
{ 
    $xmlCurrentNode = $xmlDoc.CreateElement("httpCompression") 
    $xmlDoc.SelectSingleNode("/configuration/system.webServer").AppendChild($xmlCurrentNode) 
} 
$xmlCurrentNode.SetAttribute("minFileSizeForComp", "10240") 
$xmlCurrentNode.SetAttribute("dynamicCompressionEnableCpuUsage", "70") 
write-host "Done." 

#Enable dynamic compression 
write-host "Enabling dynamic compression ..." 
$xmlCurrentNode = $xmlDoc.SelectSingleNode("/configuration/system.webServer/urlCompression") 
if ($xmlCurrentNode -eq $null) 
{ 
    $xmlCurrentNode = $xmlDoc.CreateElement("urlCompression") 
    $xmlDoc.SelectSingleNode("/configuration/system.webServer").AppendChild($xmlCurrentNode) 
} 
$xmlCurrentNode.SetAttribute("doDynamicCompression", "true") 
write-host "Done." 

#Add dynamic types for compression 
write-host "Adding dynamic types ..." 
$xmlCurrentNode = $xmlDoc.SelectSingleNode("/configuration/system.webServer/httpCompression/dynamicTypes") 
if ($xmlCurrentNode -eq $null) 
{ 
    $xmlCurrentNode = $xmlDoc.CreateElement("dynamicTypes") 
    $xmlDoc.SelectSingleNode("/configuration/system.webServer/httpCompression").AppendChild($xmlCurrentNode) 
} 
$xmlCurrentNode = $xmlDoc.SelectSingleNode("/configuration/system.webServer/httpCompression/dynamicTypes/add[@mimeType='application/*']") 
if ($xmlCurrentNode -eq $null) 
{ 
    $xmlCurrentNode = $xmlDoc.CreateElement("add") 
    $xmlCurrentNode.SetAttribute("mimeType", "application/*") 
    $xmlDoc.SelectSingleNode("/configuration/system.webServer/httpCompression/dynamicTypes").AppendChild($xmlCurrentNode) 
} 
$xmlCurrentNode.SetAttribute("enabled", "true") 
write-host "Done." 

write-host "Saving the target config file ..." 
$xmlDoc.Save("$globalConfig") 
write-host "Done." 

次は、プロジェクトでelastic beanstalk extensionsを使用する必要があります。

次のinit.configファイルをWebサイトのルートから.ebextensionsフォルダに追加します。これはYAMLファイルなので、スペースインデントはタブではありません。

files: 
    "c:/cfn/init.ps1": 
    content: | 
     $instanceDoc = Invoke-RestMethod 'http://169.254.169.254/latest/dynamic/instance-identity/document' 
     $extPath = "c:\cfn\.ebextensions" 
     if (Test-Path $extPath) { 
      Remove-Item $extPath -Recurse 
     } 
     Read-S3Object -BucketName "mys3bucket" -Folder $extPath -KeyPrefix '/ebExtensions' -Region ($instanceDoc.region) 
     . (Join-Path $extPath -ChildPath '\setup.ps1') 
container_commands: 
    00-invoke-init: 
    command: powershell.exe -nologo -noprofile -file "c:\cfn\init.ps1" 

それ以外の呼び出しでAWSの資格情報を渡す、あなたのインスタンスが役割を経由してバケットへのアクセス許可を持っていることを確認してください読み取りS3Object

は、上記で、次の

  • を行い、ファイルelastic beanstalkイベントinit.ps1という新しいファイルがc:\ cfn \ init.ps1に書き込まれます
  • コマンドイベント中にinit.ps1ファイルが実行されます。
  • init。ps1ファイルは、S3からセットアップファイルをダウンロードして実行します。 (すべてのpowershellをインラインにすることができますが、これによりYAMLがきれいに保たれ、複数のファイルを簡単に使用できるようになります)。
関連する問題