目录

针对 Windows Server 2008 Web 服务 IIS + PHP 配置的一些心得

目录

IIS 中的配置大多都可以体现在对访问日志下的 web.config 中。

一、部署 对于 IIS7 以上的可以直接进入https://www.microsoft.com/web/downloads/platform.aspx 该网站下载 Microsoft Web Platform Installer 5.0,直接搜索 php,选择自己的目标版本点击添加,然后点击安装即可。

二、配置: 以下配置均需要要加入如下结构中:

1
2
3
4
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 代码添加区域 -->
</configuration>
  1. rewrite 方法使用示例 rule.name 里的内容要唯一,否则报错。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<system.webServer>
    <rewrite>
        <rules>
            <rule name="Rewrite to Lyprx">
                <match url="^Lyprx/(.*)$"/>
                <action type="Rewrite" url="{R:1}"/>
            </rule>
            <rule name="Rewrite to PHP">
                <match url="." ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
  1. 禁止脚本执行 这里以禁止执行 php 脚本为例。可以将代码单独完成的 web.config 文件放入需要禁止执行脚本的文件目录下。
1
2
3
4
5
6
7
8
9
<system.webServer>
    <security>
        <requestFiltering>
            <fileExtensions>
                <add fileExtension=".php" allowed="false" />
            </fileExtensions>
        </requestFiltering>
    </security>
</system.webServer>