美好的一天,我在我的Linux Ubuntu 16.04服务器上设置了apache2,其中有多个域指向不同的DocumentRoot
文件夹。
我的问题是,当我使用sudo a2dissite 000-default.conf
禁用默认配置时,我的配置正常,并且所有域都指向正确的文件夹。
当我启用默认配置sudo a2ensite 000-default.conf
时,默认配置会“覆盖”其他一些.conf
文件,并指向000-default.conf
定义为DocumentRoot
的位置
以下是我的两个配置文件:
address.com.conf
<VirtualHost *:80>
ServerAdmin address@mail.com
DocumentRoot /var/www/html/betaFiles/
ServerName subdomain.address.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} = subdomain.address.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerAdmin address@mail.com
DocumentRoot /var/www/html/userweb/
ServerName address.com
ServerAlias www.address.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect /permanent https://www.address.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =address.com [OR]
RewriteCond %{SERVER_NAME} =www.address.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
000-default.conf
<VirtualHost *:80>
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
如何启用所有这些功能并仍然按照我希望的方式工作?