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

What will happen if I include vhost config file directly in "sites-enabled" folder?

· 52CE 我爱测

I am currently studying Apache virtual hosts and have some confusion regarding their configuration. I have created a virtual host file in the sites-available folder and enabled the corresponding site using the command a2ensite ex…

问题原文

原帖链接 · Khurshid Alam · CC BY-SA 4.0

I am currently studying Apache virtual hosts and have some confusion regarding their configuration.

I have created a virtual host file in the sites-available folder and enabled the corresponding site using the command a2ensite example.com.conf as root. I notice when doing so that this creates a symlink in the sites-enabled folder.

To more thoroughly understand the behaviour, I experimented by saving the example.com.conf file directly into the sites-enabled, eschewing the indirection via a symlink. After restarting Apache, I was surprised to find the virtual host continues to work fine.

If I store example.com.conf file only in sites-enabled, without storing in sites-available folder and using a symlink, will this cause any problems?

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

This folder structure is all about manageability. While it would be perfectly fine to add all module and virtual host configuration into a single httpd.conf, it would make it long and tricky to modify. Therefore, for example in Debian, wildcard includes have been used to separate the configuration into multiple files:

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

This makes everything matching path sites-enabled/*.conf to be added to the configuration, and for the Apache HTTPd it doesn't matter whether it's a text file or a symlink to one. From this perspective, it doesn't even matter whether the file has <VirtualHost> blocks in it or is just some other Apache configuration. It's also perfectly possible to have file example.com.conf with configuration for example.net etc.

The problems you will face with unconventional configuration are related to the lack of manageability:

  • You won't be able to enable or disable virtual hosts with a2ensite / a2dissite.

    # a2dissite example.com
    ERROR: Site example.com does not exist!
    
    • The official documentation (man pages) becomes useless.

    • You can't easily temporarily disable the site. E.g. a catch-all virtual host makes it easy to create an under maintenance page to show while the site is disabled for updates.

  • Someone else administering the same server may have used to use ln -s and rm instead of these official commands. While trying to temporarily disable the site, they might accidentally delete it.

  • No-one else knows you haven't been following the normal practices. In a few months you will forget it, too. At that point you will ask a new question on Serverfault regarding why following the documentation or a tutorial doesn't apply for your setup anymore.

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

资料来源与适用范围

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

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

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