是否可以为 Azure 上的 PHP Web 应用程序包含一个 web.config 文件(或等效文件)?
Is it possible to include a web.config file (or equivalent) for a PHP Web App on Azure?
我试图将对我的 PHP 站点的访问限制为特定 IP 地址,但我看到的唯一 type of documentation 这样做使用了 web.config 文件。我知道 web.config 通常用于 ASP.NET 项目,但不知道我们是否应该能够将它包含在 PHP 项目的某个地方。我试过在我的网站根目录中包含一个名为 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>
确保用您的 IP 地址替换 XXX.XXX.XXX.XXX。
我试图将对我的 PHP 站点的访问限制为特定 IP 地址,但我看到的唯一 type of documentation 这样做使用了 web.config 文件。我知道 web.config 通常用于 ASP.NET 项目,但不知道我们是否应该能够将它包含在 PHP 项目的某个地方。我试过在我的网站根目录中包含一个名为 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>
确保用您的 IP 地址替换 XXX.XXX.XXX.XXX。