LoginSignup
3
4

More than 5 years have passed since last update.

Azure AppServiceで、不要なヘッダーを消す

Posted at

Serverヘッダーを消す

wwwroot\web.configに下記の内容を追記。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    ...
    <security>
        <requestFiltering removeServerHeader="true" />
    </security>
    ...
  </system.webserver>
</configuration>

X-Powerd-By ヘッダを消す

ASP.NETPHP x.x.xで消し方が違う。

ASP.NET

wwwroot\web.configに下記の内容を追記。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    ...
    <httpProtocol>
        <customHeaders>
            <clear />
        </customHeaders>
    </httpProtocol>
    ...
  </system.webserver>
</configuration>

PHP x.x.x

これはどうも最適な消し方が無いらしい。

expose_php=Offwwwroot\.user.iniに書いても消えないので、phpスクリプトにini_setを書くか、このStackOverflowの回答を参考に下記の内容をwwwroot\web.configに書く。ヘッダーそのものは消えないが、内容は消えるので最低限の対策にはなる。

ちなみに上2つのヘッダーもこの方法で内容を消すことは出来ますが、ヘッダーの存在そのものを消すことは出来ません。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    ...
    <rewrite>
        ...
        <outboundRules rewriteBeforeCache="true">
            <rule name="Remove X-Powered-By HTTP response header">
                <match serverVariable="RESPONSE_X-Powered-By" pattern=".+" />
                <action type="Rewrite" value="" />
            </rule>
        </outboundRules>
        ...
    </rewrite>
    ...
  </system.webserver>
</configuration>
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4