Debian下/etc/apache2/sites-enabled/000-default.conf的问题
这个文件之所以命名成000-default.conf,而不是直接命名成default.conf是有原因的。
原因大概就是Apache在启动的时候会先加载这个文件里的配置作为default配置。
这是我刚刚摸索出来的。
例如,这是一个在80端口配置虚拟主机的写法(默认的/etc/apache2/sites-enabled/000-default.conf文件内容):
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
如果此时有另外一个虚拟主机配置文件像这样写,并且命名成000-a.conf:
ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
假设你的虚拟主机IP是1.2.3.4,此时启动apache2,以IP+端口的形式来访问这个站点,例如访问http://1.2.3.4:80/
你获取到的将是/var/www/example.com路径下的web文件,而不是默认的/var/www/html
推测是由于Apache先载入了000-a.conf的内容并将它作为了默认配置所导致的。
重命名000-a.conf这个文件,令它的载入顺序在000-default.conf之后,即可避免上述问题。