How to disable the default document root in Apache?
Solution 1
Thanks for the other answers. I solved it by adding a default virtual host without any permissions. The global DocumentRoot
and ServerName
options must match the ones specified in the virtual host.
/etc/httpd/conf/httpd.conf
...
ServerName <server-ip>:80
DocumentRoot "/var/www/html"
<Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
</Directory>
...
/etc/httpd/conf.d/default.conf
<VirtualHost *:80>
ServerName <server-ip>
DocumentRoot /var/www/html
</VirtualHost>
This way, I get a 403 Forbidden message when the server is accessed by it's ip directly, which is exactly what I wanted. It would be even better if I wouldn't need /var/www/html
an existing directory for that, but Apache complains if I specify something like /dev/null
instead.
Solution 2
Yes and No.
You can comment out or remove the DocumentRoot
directive, no problem. But that doesn't achieve much, because then it will default to the default directory PREFIX/htdocs/
where PREFIX is set when you build apache.
When you have VirtualHosts set up all requests that are not handled by an explicitly configured virtual host get handled by the default virtualhost (which is typically the first one, but httpd -S
will tell you).
Solution 3
I'm not sure you want to do that. If there is no default vhost in an apache config, the first defined vhost becomes the default.
All you really need to do is have the default serve a blank page.
Solution 4
Any Apache configuration file with extension .conf
located within /etc/httpd/conf.d/
will be included as part of Apache configuration. Thus to disable the default "Welcome" page configuration we need to rename its configuration /etc/httpd/conf.d/welcome.conf:
Step one move default welcome file:
sudo mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.backup
Step second reboot Appache2 service
sudo systemctl restart httpd
Related videos on Youtube
danijar
Researcher aiming to build intelligent machines based on concepts of the human brain. Website · Twitter · Scholar · Github
Updated on September 18, 2022Comments
-
danijar over 1 year
I host some websites on my server running Apache Httpd. Each website has it's own domain or sub-domain and virtual host. Therefore, I need no default document root. Is it possible to disable
DocumentRoot
in/etc/httpd/conf/httpd.conf
?