问题原文
原帖链接 · danijar · CC BY-SA 3.0
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?
社区高分解答
原帖链接 · danijar · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
