支持高并发的IIS Web服务器经常使用设置

适用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0html

适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows Server 2012web

一、应用程序池(Application Pool)的设置: windows

  • General->Queue Length设置为65535(队列长度所支持的最大值)
  • Process Model->Idle Time-out设置为0(不让应用程序池由于没有请求而回收)
  • Recycling->Regular Time Interval设置为0(禁用应用程序池按期自动回收)

二、.Net Framework相关设置浏览器

a) 在machine.config中将缓存

<processModel autoConfig="true" />

改成服务器

<processModel enable="true" requestQueueLimit="100000"/>

(保存后该设置当即生效)并发

b) 打开C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers \Default.browser,找到<defaultBrowser id="Wml" parentID="Default" >,注释<capabilities>部分,而后运行在命令行中运行aspnet_regbrowsers -i。app

复制代码
<defaultBrowser id="Wml" parentID="Default" > <identification> <header name="Accept" match="text/vnd\.wap\.wml|text/hdml" /> <header name="Accept" nonMatch="application/xhtml\+xml; profile|application/vnd\.wap\.xhtml\+xml" /> </identification> <!-- <capabilities> <capability name="preferredRenderingMime" value="text/vnd.wap.wml" /> <capability name="preferredRenderingType" value="wml11" /> </capabilities> --> </defaultBrowser>
复制代码

以解决text/vnd.wap.wml问题。负载均衡

三、IIS的applicationHost.config设置ide

设置命令:

c:\windows\system32\inetsrv\appcmd.exe set config /section:serverRuntime /appConcurrentRequestLimit:100000

设置结果:

<serverRuntime appConcurrentRequestLimit="100000" />

(保存后该设置当即生效)

四、http.sys的设置

注册表设置命令1(将最大链接数设置为10万):

reg add HKLM\System\CurrentControlSet\Services\HTTP\Parameters /v MaxConnections /t REG_DWORD /d 100000

注册表设置命令2(解决Bad Request - Request Too Long问题):

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxFieldLength /t REG_DWORD /d 32768
reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxRequestBytes /t REG_DWORD /d 32768

(须要在命令行运行 net stop http  & net start http & iisreset 使设置生效)

五、针对负载均衡场景的设置

在Url Rewrite Module中增长以下的规则:

复制代码
<rewrite> <allowedServerVariables> <add name="REMOTE_ADDR" /> </allowedServerVariables> <globalRules> <rule name="HTTP_X_Forwarded_For-to-REMOTE_ADDR" enabled="true"> <match url=".*" /> <serverVariables> <set name="REMOTE_ADDR" value="{HTTP_X_Forwarded_For}" /> </serverVariables> <action type="None" /> <conditions> <add input="{HTTP_X_Forwarded_For}" pattern="^$" negate="true" /> </conditions> </rule> </globalRules> </rewrite>
复制代码

相关博文:迁入阿里云后遇到的Request.UserHostAddress记录IP地址问题

注意事项:添加该URL重写规则会形成IIS内核模式缓存不工做,详见微软的坑:Url重写居然会引发IIS内核模式缓存不工做

六、 设置Cache-Control为public

在web.config中添加以下配置: 

复制代码
<configuration> <system.webServer> <staticContent> <clientCache cacheControlCustom="public" /> </staticContent> </system.webServer> </configuration>
复制代码

 

  1. 打开IIS Manager。
  2. 单击服务器。而后,在右侧窗口中双击HTTP Reponse Headers。
  3. 单击Add。在Name字段中,输入Cache-Control,在Value字段中,输入public。
  4. 移除X-Powered-By头。由于浏览器或代理都不使用它,因此它只会增长开销。
  5. 点击Set Common Headers。
  6. 设置Expire Web Content。选择After,指定365天。

    IIS经过Cache-Control应答头告诉浏览器和代理是否缓存能够图片。它的可能值包括:

    Cache-Control value Description
    no-cache Prevents caching in the browser or proxies.
    private Allows caching in the browser, but not in proxies. This is the default value.
    public Allowing caching in both the browser and in proxies.

    除了这个, Cache-Control: max-age头指定浏览器缓存图片的最大时间。HTTP 1.1规范建议服务器不要指定这个值超过1年。

    若是图片在缓存中,访问者刷新页面(Ctrl + F5),或者图片的max-age过时,浏览器会发送一个条件请求。这个请求有一个If-Modified-Since请求头指出缓存图片的接收时间。若是没有新版本,服务器答复304“Not Modified”。若是有新版本,服务器发送200应答,应答中包括新图片

    阻止条件请求

    任何请求都是昂贵的,即便答应是短小的,例如304应答。最好设置max-age为一年。

    若是图片修改了,怎么办?访问者要看一年旧图片?为了防止这种状况,能够在图片名中加入版本号,例如:myimage_v2.jpg。当图片更新时,图片改名myimage_v3.jpg。浏览器在缓存中不能找到新图片,就会从服务器上从新获取。

    手工更新图片名称会须要很大的工做。使用本文后面介绍的Image control adapter。

    Expires头

    Expires是在HTTP1.0中定义的。Cache-Control头始终比Expires头优先级高。如今,没有理由再使用Expires。

 

七、ASP.NET线程设置

在machine.config的<processModel>中添加以下设置: 

<processModel enable="true" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" minIoThreads="50"/>

相关博文:云计算之路-阿里云上:从ASP.NET线程角度对“黑色30秒”问题的全新分析

 

相关连接:

让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求

相关文章
相关标签/搜索