因此我这样做来设置一个新的虚拟主机:
cd /etc/apache2/sites-available
sudo touch test
sudo gedit test
我已将此内容保存在测试文件中:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test.local
DocumentRoot /home/richard/projects/test
</VirtualHost>
然后我做了:
mkdir /home/richard/projects/test
touch /home/richard/projects/test/index.html
sudo gedit /etc/hosts
我已将 hosts 文件编辑如下:
127.0.0.1 localhost
127.0.1.1 richard-desktop
127.0.0.1 test.local
127.0.0.1 test2.local
127.0.0.1 test3.local
# 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
然后我做了:
sudo a2ensite test
sudo a2dissite default
sudo service apache2 reload
然后我进入浏览器:
http://test.local
但它不起作用,页面一直在加载。
netstat -plnt |grep 80 的输出:
richard@richard-desktop:/etc/apache2/sites-available$ sudo netstat -plnt |grep 80
[sudo] password for richard:
tcp6 0 0 :::80 :::* LISTEN 1265/apache2
netstat -taupen | grep :80: 的输出
tcp 0 0 10.200.32.82:36199 77.67.21.59:80 ESTABLISHED 1000 88789 4410/firefox
tcp 0 0 127.0.0.1:56686 127.0.0.1:80 ESTABLISHED 1000 88490 4410/firefox
tcp 0 0 127.0.0.1:56775 127.0.0.1:80 ESTABLISHED 1000 87786 4410/firefox
tcp 0 0 10.200.32.82:35054 31.186.231.25:80 TIME_WAIT 0 0 -
tcp 0 0 10.200.32.82:37231 64.34.119.12:80 ESTABLISHED 1000 89616 4410/firefox
tcp 0 0 10.200.32.82:60212 173.194.34.99:80 ESTABLISHED 1000 87876 4410/firefox
tcp 1 0 10.200.32.82:44111 91.189.89.134:80 CLOSE_WAIT 1000 94528 2159/python
tcp 0 0 10.200.32.82:46205 173.194.34.97:80 ESTABLISHED 1000 87879 4410/firefox
tcp 0 0 127.0.0.1:56684 127.0.0.1:80 ESTABLISHED 1000 93631 4410/firefox
tcp 1 0 10.200.32.82:44112 91.189.89.134:80 CLOSE_WAIT 1000 94529 2159/python
tcp 0 0 10.200.32.82:47009 77.67.21.48:80 ESTABLISHED 1000 96368 4410/firefox
tcp 0 0 10.200.32.82:36200 77.67.21.59:80 ESTABLISHED 1000 88790 4410/firefox
tcp 0 0 10.200.32.82:35053 31.186.231.25:80 TIME_WAIT 0 0 -
tcp 0 0 10.200.32.82:33628 92.123.67.88:80 ESTABLISHED 1000 93931 4410/firefox
tcp 0 0 10.200.32.82:46999 77.67.21.48:80 ESTABLISHED 1000 88794 4410/firefox
tcp 0 0 10.200.32.82:50668 64.34.119.101:80 ESTABLISHED 1000 87923 4410/firefox
tcp 0 0 10.200.32.82:46991 77.67.21.48:80 ESTABLISHED 1000 96363 4410/firefox
tcp 0 0 127.0.0.1:56681 127.0.0.1:80 ESTABLISHED 1000 93629 4410/firefox
tcp 1 0 10.200.32.82:58695 91.189.89.144:80 CLOSE_WAIT 1000 7844 2011/ubuntu-geoip-p
tcp 0 0 10.200.32.82:34946 173.194.67.95:80 ESTABLISHED 1000 93950 4410/firefox
tcp 0 0 10.200.32.82:56595 77.67.21.56:80 ESTABLISHED 1000 93933 4410/firefox
tcp 0 0 10.200.32.82:57734 77.67.21.35:80 ESTABLISHED 1000 93956 4410/firefox
tcp 0 0 10.200.32.82:36203 77.67.21.59:80 ESTABLISHED 1000 88793 4410/firefox
tcp 0 0 127.0.0.1:56679 127.0.0.1:80 ESTABLISHED 1000 93627 4410/firefox
tcp 0 0 127.0.0.1:56677 127.0.0.1:80 ESTABLISHED 1000 86821 4410/firefox
tcp 0 0 10.200.32.82:49652 50.112.101.148:80 ESTABLISHED 1000 93939 4410/firefox
tcp 0 0 10.200.32.82:44859 184.73.242.29:80 ESTABLISHED 1000 96374 4410/firefox
tcp 0 0 10.200.32.82:47811 23.21.113.66:80 ESTABLISHED 1000 87908 4410/firefox
tcp 0 0 10.200.32.82:46996 77.67.21.48:80 ESTABLISHED 1000 88791 4410/firefox
tcp 0 0 10.200.32.82:52730 173.194.41.133:80 ESTABLISHED 1000 93958 4410/firefox
tcp 0 0 10.200.32.82:32952 64.34.119.13:80 ESTABLISHED 1000 96383 4410/firefox
tcp 0 0 127.0.0.1:56678 127.0.0.1:80 ESTABLISHED 1000 87612 4410/firefox
tcp 0 0 127.0.0.1:56897 127.0.0.1:80 ESTABLISHED 1000 93903 4410/firefox
tcp 0 0 10.200.32.82:36197 77.67.21.59:80 ESTABLISHED 1000 88787 4410/firefox
tcp 0 0 10.200.32.82:36202 77.67.21.59:80 ESTABLISHED 1000 88792 4410/firefox
tcp 0 0 10.200.32.82:36198 77.67.21.59:80 ESTABLISHED 1000 88788 4410/firefox
tcp6 0 0 :::80 :::* LISTEN 0 13912 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56678 ESTABLISHED 0 0 -
tcp6 300 0 127.0.0.1:80 127.0.0.1:56681 ESTABLISHED 0 0 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56897 ESTABLISHED 0 0 -
tcp6 289 0 127.0.0.1:80 127.0.0.1:56686 ESTABLISHED 0 0 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56775 ESTABLISHED 0 0 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56684 ESTABLISHED 0 0 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56677 ESTABLISHED 0 0 -
tcp6 290 0 127.0.0.1:80 127.0.0.1:56679 ESTABLISHED 0 0 -
答案1
我认为问题出在监听端口。根据您的输出,它只监听 IPv6,而不监听 IPv4,这就是页面始终在加载的原因。
根据您的 netstat 命令的输出:
tcp6 0 0 :::80 :::* LISTEN 0 13912 -
您必须更改 /etc/apache2/ports.conf 以使其也能监听 ipv4 地址。
/etc/apache2/ports.conf
在文件中添加以下行:
Listen 0.0.0.0:80