强化 IIS 中的上传文件夹会破坏图像

Hardening uploads folder in IIS breaks images

我的站点使用直接 URLs 从上传文件夹加载一堆图像,例如:

http://www.example.com/wp-content/uploads/some.image.png

我正在尝试解决远程脚本执行问题,https://codex.wordpress.org/Hardening_WordPress 上推荐的一件事是使用 .htaccess 文件防止上传文件夹中的脚本执行:

# Kill PHP Execution
<Files ~ "\.ph(?:p[345]?|t|tml)$">
   deny from all
</Files>

我的站点在 IIS 上 运行,因此为了获得相同的结果,我删除了上传文件夹及其所有子文件夹的 PHP 处理程序:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>
        <handlers>
           <remove  name="php-7.1.7" />
        </handlers>
    </system.webServer>
</configuration>

但是,如果我使用 web.config 文件,使用直接 URL 加载图像会导致 http 500 错误。因此,主题无法正确加载。

如何在不中断静态文件加载的情况下阻止 PHP 脚本在上传文件夹中执行?

<remove name="php-7.1.7" /> 下面添加 <add name="StaticFile" /> 没有区别。

在上传文件夹中创建一个 web.config 并粘贴以下内容 xml:

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