估计还是有很多老的服务器还在运行着Win2003,默认的IIS 6在整合多种技术很麻烦,其ISAPI扩展主要用于处理某一类型的文件,IIS 7的模块化设计,其扩展性远胜于IIS6,Win2003没有办法安装IIS7,但可以使用IIS Express 7.5,它的功能差不多,只是没有界面而已。下面就是利用IIS Express 7.5分别整合ASP、ASP.net、PHP和Tomcat的配置步骤。

IIS配置文件存放路径

  • IIS 5 中,IIS的配置文件在:C:\WINNT\system32\inetsrv\MetaBase.bin
  • IIS 6 中,IIS 的配置文件在:C:\WINDOWS\system32\inetsrv\MetaBase.xml
  • IIS 7 中,IIS 的配置文件在:C:\WINDOWS\system32\inetstr\config\applicationHost.config 修改这个文件需要把iis对应的服务关掉,这样才能修改这个文件,通过DirectoryEntry类可以修改此文件实现程序配置IIS。
  • IIS Express中,配置文件在:C:\Users\用户名\Documents\IISExpress\config\applicationHost.config

IIS Express相当于没有界面的IIS,可以用它来替代IIS 5或者IIS 6,IIS Express功能与IIS 7是相当的,目前版本的版本有: IIS Express 7.5及以上都需要.NET Framework 4.0 系统要求:Windows 7, Windows Server 2003, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP

IIS Express 8.0 系统要求:Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Vista Service Pack 1

1 下载并安装最新版的IISExpress 7.5

Vista版本以下的系统选择7.5,以上版本可以选择8.0 [点击下载](https://www.microsoft.com/zh-CN/download/details.aspx?id=1038) IIS Express主要应用于开发环境中,并发连接数是有一定限制的,找到配置文件"applicationHost.config",修改maxConnections属性。

<sites>
<!-- Other sites -->
<site name="YourSiteName" id="YourSiteId">
<!-- Existing elements -->
<limits maxBandwidth="65536" maxConnections="1024" connectionTimeout="00:01:00" />
</site>
<!-- Remaining sites -->
</site>

2 整合ASP

打开IIS Express的配置文件C:\Documents and Settings\$YourName$\My Documents\IISExpress\config\applicationHost.config

找到<system.applicationHost>和<system.webServer>节点添加如下代码:

<system.applicationHost>
<sites>
<site name="website" id="834668867" serverAutoStart="true">
<application path="/" applicationPool="Clr2ClassicAppPool">
<virtualDirectory path="/" physicalPath="D:\website" />
<virtualDirectory path="/jakarta" physicalPath="d:\jk\isapi" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:" />
</bindings>
</site>
</sites>
</system.applicationHost>
<system.webServer>
<asp
enableParentPaths="true"
bufferingOn="true"
errorsToNTLog="true"
appAllowDebugging="true"
appAllowClientDebug="true"
scriptErrorSentToBrowser="true">

<session allowSessionState="true" />
<cache diskTemplateCacheDirectory="%TEMP%\iisexpress\ASP Compiled Templates" />
<limits />
</asp>
</system.webServer>

3 整合PHP

1.[下载php-5.2.17-Win32-VC6-x86.zip](http://windows.php.net/downloads/releases/archives/php-5.2.17-Win32-VC6-x86.zip) 需要配置的程序是很多年前写的,当时是针对5.2.17开发的,更新的版本应该也是可以参照以下的配置方法。PHP 5.4版本是用VC9编写的,需要另外安装VC9运行环境[Microsoft Visual C++ 2008 Redistributable Package](http://www.microsoft.com/zh-cn/download/details.aspx?id=29)。

2.我的文档/IISExpress目录里面有个applicationHost.

<defaultDocument enabled="true">
<files>
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
<add value="index.php" />
</files>
</defaultDocument>

3.找到<fastcgi/>节点,添加


<fastCgi>
<application fullPath="D:\PHP\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="600" requestTimeout="600" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="D:\PHP" />
</environmentVariables>
</application>
</fastCgi>

4.找到<handlers>节点,添加


<add name="PHP53_via_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="D:\PHP\php-cgi.exe" resourceType="Either" />

尤其要注意的一是,这一句最好加在最前面,也就是在<handlles>下面的第一句,避免被其它Handle抢先处理了。以上配置中,D:\php\php-cgi.exe的部分替换成自己的php文件夹中的php-cgi.exe的位置。

5.在<site>节点下,直接修改站点信息,或直接用appcmd.exe add site来添加站点。

6.找到诸如wordpress的安装文件夹,创建一个web.config文件,在configuration配置节下,添加Gzip压缩规则。

7.同样在web.config中,Wordpress的rewrite完整的web.config文件内容如下:

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
</configuration>

这样就完全配置完毕了,然后在IIS7 Express目录下,找到IISExpress.exe,直接双击运行,或者用命令行来执行指定加载哪个站点。 为了方便使用,可以将IISExpress安装目录添加到Path环境变量中。

iisexpress.exe /site:"站点名称1"
iisexpress.exe /site:"站点名称2"

4 整合tomcat

1.安装tomcat 服务器上的网站是用tomcat 6.x开发的,目前最高版本是6.0.45,下载地址:http://tomcat.apache.org/download-60.cgi。 我把tomcat安装到了d: 2.下载tomcat-connector 将IIS的请求转发到tomcat上需要tomcat-connector,目前最高版本是1.2.40,下载地址:http://mirror.bit.edu.cn/apache/tomcat/tomcat-connectors/jk/binaries/windows/ 把connector解压到d:\jk

d:\jk    
├── conf  
│   ├── uriworkermap.properties
│   └── workers.properties
├── isapi  
│   ├── isapi_redirect.dll
│   ├── isapi.redirect.properties
│   └── web.config
├── logs  
└── tomcat_isapi.reg  

uriworkermap.properties

workers.tomcat_home=D:\Tomcat\
workers.java_home=C:\Program Files\Java\jre1.6.0_04
ps=\
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

workers.properties

/$your_website_url/*=ajp13

isapi.redirect.properties

# Configuration file for the Jakarta ISAPI Redirector

# The path to the ISAPI Redirector Extension, relative to the website
# This must be in a virtual directory with execute privileges
extension_uri=/jakarta/isapi_redirect.dll

# Full path to the log file for the ISAPI Redirector
log_file=d:\jk\logs\isapi_redirect.log

# Log level (debug, info, warn, error or trace)
log_level=info

# Full path to the workers.properties file
worker_file=d:\jk\conf\workers.properties

# Full path to the uriworkermap.properties file
worker_mount_file=d:\jk\conf\uriworkermap.properties

web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Write, Execute" />
</system.webServer>
</configuration>

tomcat_isapi.reg


Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Jakarta Isapi Redirector\1.0]
"extension_uri"="/jakarta/isapi_redirect.dll"
"log_file"="D://jk//logs//isapi.log"
"log_level"="debug"
"worker_file"="D://jk//conf//workers.properties"
"worker_mount_file"="D://jk//conf//uriworkermap.properties"

5 后记

在使用Nginx反向代理方案流行之后,已经很少再使用这样的配置方案了,把同一域名下的子站点URL映射到不同的监听端口,更简单和壮健,而且更容易整合不同的技术。

Last Updated 2018-10-14 日 23:38.
Created by Emacs 25.1.1 (Org mode 9.1.14)