我试图将对我的PHP站点的访问限制在特定的IP地址,但我看到的唯一类型的文档使用web.config文件。我知道web.config通常用于ASP.NET项目,但不知道我们是否应该将其包含在PHP项目中。我尝试在我的web根目录中包含一个名为web.config的空文件,但在请求网站时,The page cannot be displayed because an internal server error has occurred.
会显示为页面。
是否有合适的位置将其粘贴在我的目录中,是否有特定的配置方式,或者是否有其他类型的文件可以包含在相当于web.config的位置?
是的,您绝对可以使用php页面和web.config来完成此操作。请确保web.config位于网站的根文件夹中。
请看下面我的代码,它工作得很完美。我推送到以下网站进行测试:http://php-ip-restrict-110515.azurewebsites.net/
我的index.php文件
<!DOCTYPE html>
<html>
<body>
<?php
echo "My test PHP script!";
?>
</body>
</html>
我的web.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<security>
<ipSecurity allowUnlisted="false" denyAction="NotFound">
<add allowed="true" ipAddress="XXX.XXX.XXX.XXX" />
</ipSecurity>
</security>
</system.webServer>
</configuration>
请确保将XXX.XXX.XXX.XXX替换为您的Ip地址。