• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

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

    发布者: 竹韵9933 | 发布时间: 2025-8-15 05:37| 查看数: 88| 评论数: 0|帖子模式

    适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows Server 2012
    1、应用程序池(Application Pool)的设置:

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

    2、.Net Framework相关设置
    a) 在machine.config中将
    1. <processModel autoConfig="true" />
    复制代码
    改为
    1. <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。
    1. <defaultBrowser id="Wml" parentID="Default" >
    2.     <identification>
    3.         <header name="Accept" match="text/vnd\.wap\.wml|text/hdml" />
    4.         <header name="Accept" nonMatch="application/xhtml\+xml; profile|application/vnd\.wap\.xhtml\+xml" />
    5.     </identification>
    6. <!--
    7.     <capabilities>
    8.         <capability name="preferredRenderingMime"              value="text/vnd.wap.wml" />
    9.         <capability name="preferredRenderingType"              value="wml11" />
    10.     </capabilities>
    11. -->
    12. </defaultBrowser>
    复制代码
    以解决text/vnd.wap.wml问题。
    3、IIS的applicationHost.config设置
    设置命令:
    1. c:\windows\system32\inetsrv\appcmd.exe set config /section:serverRuntime /appConcurrentRequestLimit:100000
    复制代码
    设置结果:
    1. <serverRuntime appConcurrentRequestLimit="100000" />
    复制代码
    (保存后该设置立即生效)
    4、http.sys的设置
    注册表设置命令1(将最大连接数设置为10万):
    1. reg add HKLM\System\CurrentControlSet\Services\HTTP\Parameters /v MaxConnections /t REG_DWORD /d 100000
    复制代码
    注册表设置命令2(解决Bad Request - Request Too Long问题):
    1. reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxFieldLength /t REG_DWORD /d 32768
    2. reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters /v MaxRequestBytes /t REG_DWORD /d 32768
    复制代码
    (需要在命令行运行 net stop http  & net start http & iisreset 使设置生效)
    5、针对负载均衡场景的设置
    在Url Rewrite Module中增加如下的规则:
    1. <rewrite>
    2.     <allowedServerVariables>
    3.         <add name="REMOTE_ADDR" />
    4.     </allowedServerVariables>
    5.     <globalRules>
    6.         <rule name="HTTP_X_Forwarded_For-to-REMOTE_ADDR" enabled="true">
    7.             <match url=".*" />
    8.             <serverVariables>
    9.                 <set name="REMOTE_ADDR" value="{HTTP_X_Forwarded_For}" />
    10.             </serverVariables>
    11.             <action type="None" />
    12.             <conditions>
    13.                 <add input="{HTTP_X_Forwarded_For}" pattern="^$" negate="true" />
    14.             </conditions>
    15.         </rule>
    16.     </globalRules>
    17. </rewrite>
    复制代码
    相关博文:迁入阿里云后遇到的Request.UserHostAddress记录IP地址问题
    注意事项:添加该URL重写规则会造成IIS内核模式缓存不工作,详见微软的坑:Url重写竟然会引起IIS内核模式缓存不工作
    6、 设置Cache-Control为public
    在web.config中添加如下配置:
    1. <configuration>
    2.     <system.webServer>
    3.         <staticContent>
    4.             <clientCache cacheControlCustom="public" />
    5.         </staticContent>
    6.     </system.webServer>
    7. </configuration>
    复制代码
    7、ASP.NET线程设置
    在machine.config的<processModel>中添加如下设置:
    1. <processModel enable="true" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" minIoThreads="50"/>
    复制代码
    相关博文:云计算之路-阿里云上:从ASP.NET线程角度对“黑色30秒”问题的全新分析
    8、修改TCP MaxUserPort限制
    由默认5000改为65534,修改方法:在注册表 HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters 中添加名为MaxUserPort,类型为DWORD(32-bit),值为65534(10进制)的项目并重启计算机。

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    ×

    最新评论

    浏览过的版块

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表