【问题标题】:Azure Websites PHP API - 405 Method Not Allowed on PUT and DELETEAzure 网站 PHP API - PUT 和 DELETE 上不允许使用 405 方法
【发布时间】:2013-04-01 06:19:11
【问题描述】:

我正在使用 Azure 网站构建一个简单的 PHP Web 服务,但无法让它支持 PUT 和 DELETE http 方法。假设它必须进入 web.config 文件 - 我已经尝试了一些来自互联网的选项,但它们似乎都不能正常运行。有什么想法吗?

这是当前的 web.config 文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
    </handlers>
    <security>
    </security>
    <directoryBrowse enabled="false" />
    <caching>
      <profiles>
        <add extension=".php" policy="DontCache" kernelCachePolicy="DontCache" />
        <add extension=".html" policy="CacheForTimePeriod" kernelCachePolicy="CacheForTimePeriod" duration="14:00:00" />
      </profiles>
    </caching>
    <rewrite>
      <rules>
        <rule name="block favicon" stopProcessing="true">
          <match url="favicon\.ico" />
          <action type="CustomResponse" statusCode="404" subStatusCode="1"
          statusReason="The requested file favicon.ico was not found"
          statusDescription="The requested file favicon.ico was not found" />
        </rule>
        <rule name="Cols Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
    <defaultDocument>
      <files>
        <remove value="index.php" />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

【问题讨论】:

  • 前几天看到了一个类似的帖子。在那种情况下,事实证明 PUT 动词被内部网络阻止了。你能检查一下这里不是这样吗?

标签: azure web-config azure-web-app-service http-method


【解决方案1】:

我没有看到您在 web.config 中添加了处理程序。我没有亲自测试过,但有人建议 PUT 和 DELETE 应该与 Windows Azure 网站一起使用,但是您需要通过 web.config 在 Windows Azure 网站上正确配置它们。

以下是您可以用来设置它的简单配置:

<configuration>
 <system.webServer>
    <handlers>
        <remove name="PHP53_via_FastCGI" />
        <add name="PHP53_via_FastCGI" path="*.php"
               verb="GET, PUT, POST, HEAD, DELETE" 
               modules="FastCgiModule" 
               scriptProcessor="D:\Program Files (x86)\PHP\v5.3\php-cgi.exe"
               resourceType="Either" requireAccess="Script" />
    </handlers>
 </system.webServer>
</configuration>

【讨论】:

【解决方案2】:

最后一个选项 DELETE 不起作用,这里是针对 Azure 上的 PHP54 修改的代码。但是感谢 Avkash!

<handlers> 
    <remove name="PHP54_via_FastCGI" />
        <add name="PHP54_via_FastCGI" path="*.php"
               verb="GET, PUT, POST, DELETE, HEAD" 
               modules="FastCgiModule" 
               scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe"
               resourceType="Either" requireAccess="Script" />
    </handlers>

【讨论】:

  • 现在 HEAD 是最后一个选项,它停止工作。我在 HEAD 之后添加了一个逗号,现在它又可以工作了。很奇怪。
猜你喜欢
  • 2019-10-28
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 2023-03-23
  • 2021-02-04
相关资源
最近更新 更多