在Ubuntu 16.04上运行
我试图将2个域名指向同一台服务器并让它们解析到不同的目录。 Domain1位于根html目录中,Domain2位于子目录中。
当我创建一个新的虚拟主机文件,以便我可以将另一个域名指向服务器(及其自己的目录)并启用它时,它会将现有域名指向新目录而不是原始目录。
VirtualHost1 (默认情况下已停用,所以不确定原因,但是当我启用它时,apache2会完全停止工作)
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
VirtualHost2
<VirtualHost *:80>
ServerName www.domain2.com
ServerAlias domain2.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/domain2
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
主机
127.0.0.1 localhost
127.0.0.1 domain1.com
127.0.0.1 domain1
203.100.111.150 domain1.com
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
输出apache2ctl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.domain1.com (/etc/apache2/sites-enabled/domain1.com.conf:1)
port 80 namevhost www.domain1.com (/etc/apache2/sites-enabled/domain1.com.conf:1)
alias domain1.com
port 80 namevhost webadmin.domain1.com (/etc/apache2/sites-enabled/services.conf:1)
alias localhost
alias 127.0.0.1
alias domain1.net
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
以下是services.config中的内容
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName webadmin.domain1.com
ServerAlias localhost 127.0.0.1 domain1.net
SetEnvIf X-Forwarded-Proto https HTTPS=on
<Directory /var/www/html>
DirectoryIndex index.html index.php
Options -Indexes
AllowOverride All
</Directory>
Options -Indexes
ErrorLog /var/log/apache2/services_error.log
TransferLog /var/log/apache2/services_access.log
</VirtualHost>
当我启用两个VirtualHost文件时,一切都停止工作。此外,当我添加到HOSTS文件domain2时,我得到503坏网关。
当然,除了非SSL之外,SSL应该为所有这些启用,但这也不起作用。不确定是谁设置这个我们在这里做了所以我希望找到一些答案,所以我可以解决它。干杯!