iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🙆

[Apache] Non-existent paths in Directory directives do not trigger syntax errors

に公開

What Happened

I wrote an Apache configuration file to apply IP restrictions to a specific directory of a web application.
I performed a syntax check using the httpd -t command, and since it returned Syntax OK, I reloaded the Apache configuration file.
To confirm that the settings were applied, I tried accessing it, but it was still accessible as usual.

Configuration Details

The following is an illustrative example of the content.

site.conf
<VirtualHost xxx.xxx.xxx.xxx:443>
  ServerName hoge.example.com

  DocumentRoot /var/www/html/hoge.example.com/public

  <Directory /var/www/html/hoeg.example.com/public>
    Require ip yyy.yyy.yyy.yyy
  </Directory>

  # Omitting the rest
</VirtualHost>

The Reason Why the IP Restriction Wasn't Working

The path in the Directory directive was a non-existent path.

- <Directory /var/www/html/hoeg.example.com/public>
+ <Directory /var/www/html/hoge.example.com/public>

After correcting the path in the settings and reloading the configuration, the IP restriction started working.

It seems that httpd -t does not return an error even if the path in the Directory directive does not exist.
Since an error occurs if the DocumentRoot is incorrect, I assumed the same behavior for the Directory directive path, which is why it took me some time to find the cause.

GitHubで編集を提案

Discussion