当前位置: 代码网 > 服务器>服务器>win服务器 > 让IIS支持高并发的Web服务器常用设置

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

2024年05月12日 win服务器 我要评论
适用的windows版本:windows server 2008, windows server 2008 r2, windows server 20121、应用程序池(application poo

适用的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中将

<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。

<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问题。

3、iis的applicationhost.config设置

设置命令:

c:\windows\system32\inetsrv\appcmd.exe set config /section:serverruntime /appconcurrentrequestlimit:100000

设置结果:

<serverruntime appconcurrentrequestlimit="100000" />

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

4、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 使设置生效)

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

在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内核模式缓存不工作

6、 设置cache-control为public

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

<configuration>
    <system.webserver>
        <staticcontent>
            <clientcache cachecontrolcustom="public" />
        </staticcontent>
    </system.webserver>
</configuration>

7、asp.net线程设置

在machine.config的<processmodel>中添加如下设置: 

<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进制)的项目并重启计算机。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com