Tag Archives: Azure

Azure App Service how to change the ‘HTTP Strict Transport Security’ ?

The HTTP Strict Transport Security can be changed by modifying the coutboundRules section of the web.config as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <outboundRules>
      <!-- here we change the 'HTTP Strict Transport Security' -->
        <rule name="Add Strict-Transport-Security only when using HTTPS" enabled="true">
          <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
          </conditions>
          <action type="Rewrite" value="max-age=31536000; includeSubdomains; preload" />
        </rule>
      </outboundRules>
    </rewrite>
  </system.webServer>
</configuration>

Azure App Service how to remove the custom headers X-Frame-Options; X-XSS-Protection; X-Content-Type-Options ?

The custom headers can be removed by modifying the customHeaders section of the web.config as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
  </system.web>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By"/>
        <clear/>

        <!-- here we remove custom headers -->
        <add name="X-Frame-Options" value="SAMEORIGIN"/>
        <add name="X-Xss-Protection" value="1; mode=block"/>
        <add name="X-Content-Type-Options" value="nosniff"/>
        <!-- here we remove custom headers -->

        <add name="Referrer-Policy" value="strict-origin-when-cross-origin"/>
        <add name="Permissions-Policy" value="accelerometer=(self), camera=(self), geolocation=(self), gyroscope=(self), magnetometer=(self), microphone=(self), payment=(self), usb=(self)"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>]
</configuration>

Azure App Service, how to change max upload (& max post) size from default 8MB also for PhpMyAdmin ?

  1. App service -> Configuration -> + App Configuration Settings
  2. Add Name: ‘PHP_INI_SCAN_DIR’
  3. Add Value: ‘D:\home\site\ini’

4. via Kudu in location ‘D:\home\site\ini’ we are adding file .extensions.ini

5. in that file we are adding two lines:

Then add the following into the file these lines: 
upload_max_filesize=1024M
post_max_size=1024M

Azure App Service WordPress Database connection wp-config.php

For connect do Azure App Service MySQL in App you need to modify wp-config.php file on the top:


$connectstr_dbhost = '';
$connectstr_dbname = '';
$connectstr_dbusername = '';
$connectstr_dbpassword = '';

foreach ($_SERVER as $key => $value) {
    if (strpos($key, "MYSQLCONNSTR_localdb") !== 0) {
        continue;
    }
    
    $connectstr_dbhost = preg_replace("/^.*Data Source=(.+?);.*$/", "\\1", $value);
    $connectstr_dbname = preg_replace("/^.*Database=(.+?);.*$/", "\\1", $value);
    $connectstr_dbusername = preg_replace("/^.*User Id=(.+?);.*$/", "\\1", $value);
    $connectstr_dbpassword = preg_replace("/^.*Password=(.+?)$/", "\\1", $value);
}


define('DB_NAME', $connectstr_dbname);

define('DB_USER', $connectstr_dbusername);

define('DB_PASSWORD', $connectstr_dbpassword);

define('DB_HOST', $connectstr_dbhost);

Azure App Service outputs error when it receives a long URL. How do I fix this?

Open your Azure Portal. Go to App Service which you are using to host your CMS/Website.
Click on Advanced Tools.
1. Click Go. It will open Kudu App Service.
2. Click on Debug console >> CMD.
3. From the top explorer navigation, go to site/wwwroot and find your web.config file (if you do not have it, create it)
4. Click edit
5. It will open editor for you to edit your web.config file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <customErrors mode="Off"/>
    <httpRuntime maxQueryStringLength = "10000" />
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxQueryString="10000" />
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

Adding mimeType in Azure App Service

When running web apps using Azures App Service Plan you may occasionally run into a problem where files or resources you have uploaded are not found even though they are where they should be. This usually results in a 404 error. Basic example of web.config file for supporting mimeType’s

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
</system.web>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".ogm" mimeType="video/ogv" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
<mimeMap fileExtension=".js.min" mimeType="text/javascript" />
<mimeMap fileExtension=".json" mimeType="application/json" />
<mimeMap fileExtension=".ico" mimeType="image/x-icon" />
</staticContent>
</system.webServer>
</configuration>