我已经在我的 Ubuntu 20.04 服务器上安装了 Apache2,并为我的两个不同的网站创建了虚拟主机。
这个想法是为dog.com以及不同的内容英国猫业公司
我在 /var/www 下创建了单独的目录,并相应地授予了所有权和权限,以便两个网站都能正常运行。
如果我关闭其中一个虚拟主机
sudo a2dissite dog.com.conf
sudo systemctl reload apache2
并转到dog.com或者英国猫业公司然后是英国猫业公司为两个地址提供服务。
如果我启用dog.com.conf但禁用另一个,如下所示:
sudo a2ensite dog.com.conf
sudo a2dissite cat.co.uk.conf
sudo systemctl reload apache2
我去dog.com或者英国猫业公司然后是dog.com显示两个地址。
如果我同时启用两者:
sudo a2ensite dog.com.conf
sudo a2ensite cat.co.uk.conf
sudo systemctl reload apache2
并前往dog.com或者英国猫业公司两次的内容英国猫业公司 并显示。理想情况下,不同的地址应该显示不同的内容。
以下是一些命令的输出,这些命令应该可以概述我的情况
tomas@ubuntu:~$ apache2ctl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server www.cat.co.uk (/etc/apache2/sites-enabled/cat.co.uk.conf:1)
port 80 namevhost www.cat.co.uk (/etc/apache2/sites-enabled/cat.co.uk.conf:1)
alias cat.co.uk
port 80 namevhost www.dog.com (/etc/apache2/sites-enabled/dog.com.conf:1)
alias dog.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
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`
内容猫科动物:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.cat.co.uk
ServerAlias cat.co.uk
DocumentRoot /var/www/cat.co.uk
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
内容dog.com.conf:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.dog.com
ServerAlias dog.com
DocumentRoot /var/www/dog.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
当apache2ctl -S
我跑步的时候AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message
所以我ServerName localhost
在最后补充道/etc/apache2/apache2.conf错误消失了
我的/etc/hosts文件内容:
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.1.1 ubuntu
164.133.173.127 dog.com
164.133.173.127 cat.co.uk
我的 IP
tomas@ubuntu:~$ ip addr show eno0
2: eno0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:22:4d:7b:48:bd brd ff:ff:ff:ff:ff:ff
inet 164.133.173.127/24 brd 164.132.173.255 scope global dynamic eno0
valid_lft 79549sec preferred_lft 79549sec
inet6 2001:41d0:1008:2181::1/56 scope global
valid_lft forever preferred_lft forever
inet6 fe80::222:4dff:fe7b:48bd/64 scope link
valid_lft forever preferred_lft forever
域名系统
tomas@ubuntu:~$ host dog.com
dog.com has address 184.169.131.242
tomas@ubuntu:~$ host cat.co.uk
cat.co.uk has address 184.169.131.242
我该如何解决这个问题?