大网数据广告活动
服务器运维问答

Does Apache2 have a way of setting global vHosts?

· 52CE 我爱测

I can't find anywhere which states if I can set a default virtual host config. I know you have 000-default.conf which is used when no vHost is found, but what about if I want to set a default config on all directories within /var…

问题原文

原帖链接 · Buckket5 · CC BY-SA 3.0

I can't find anywhere which states if I can set a default virtual host config. I know you have 000-default.conf which is used when no vHost is found, but what about if I want to set a default config on all directories within /var/www?

Say if I want to use this "default" global virtual host file to set Options -Indexes, I would then want Apache to set this on any directory in /var/www unless stated otherwise by the virtual host of the domain name.

Is this something that is possible, if so could you show me how?

已采纳解答

原帖链接 · Daniel Ferradal · CC BY-SA 3.0

If you want to set a default configuration for /var/www directory that applies to any virtualhost you define unless it was manually defined somewhere else, then you have to define this directory configuration in the previous hierarchical context to Virtualhost, that is, server config (global configuration).

For instance, if you don't want Indexes enabled by default for the documentroot path in /var/www, and your main configuration file is httpd.conf or apache2.conf, there you just have to add:

<Directory /var/www>
Options -Indexes
#any other config here
</Directory>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。