我跟着本教程设置Apache虚拟主机,但浏览器无法提供主页服务。
这是我的 .conf 文件
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName ednet.dev
ServerAlias www.ednet.dev
DocumentRoot /var/www/html/ednet/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我的主机文件
127.0.0.1 localhost
127.0.1.1 asad-HP-ProBook-4530s
127.0.0.1 ednet.dev
# 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
但当我尝试ednet.dev
在浏览器中打开时出现错误
This site can’t be reached
ednet.dev refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
sudo netstat -na | grep 80
输出
asad@asad-HP-ProBook-4530s:~$ sudo netstat -na | grep 80
tcp 0 0 10.99.2.62:41650 104.244.43.80:443 ESTABLISHED
tcp 0 0 10.99.2.62:38314 216.58.208.83:80 ESTABLISHED
tcp6 0 0 :::80 :::* LISTEN
udp 0 0 10.99.2.62:38808 216.58.198.2:443 ESTABLISHED
unix 2 [ ] DGRAM 147808
unix 3 [ ] STREAM CONNECTED 28097
unix 3 [ ] STREAM CONNECTED 28080 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 32880
unix 3 [ ] STREAM CONNECTED 28098 @/tmp/dbus-EvBU16isPp
unix 3 [ ] STREAM CONNECTED 28680
unix 3 [ ] STREAM CONNECTED 28074 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 27800 @/tmp/ibus/dbus-HdPg5eVU
unix 3 [ ] STREAM CONNECTED 28062 @/tmp/dbus-EvBU16isPp
unix 3 [ ] STREAM CONNECTED 48980
unix 3 [ ] STREAM CONNECTED 19180 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 28081 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 25580 @/tmp/dbus-EvBU16isPp
unix 2 [ ] DGRAM 28073
unix 3 [ ] STREAM CONNECTED 39680
unix 3 [ ] STREAM CONNECTED 28099 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 129780
unix 3 [ ] STREAM CONNECTED 28059
unix 3 [ ] DGRAM 24180
unix 3 [ ] STREAM CONNECTED 28066
unix 3 [ ] STREAM CONNECTED 28061 @/tmp/dbus-EvBU16isPp
unix 3 [ ] STREAM CONNECTED 58380
unix 3 [ ] STREAM CONNECTED 28060
unix 3 [ ] STREAM CONNECTED 28096
unix 3 [ ] STREAM CONNECTED 40808 @/tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 28065 @/tmp/dbus-EvBU16isPp
unix 3 [ ] STREAM CONNECTED 28056
unix 3 [ ] STREAM CONNECTED 20780
unix 2 [ ] STREAM CONNECTED 22801
unix 3 [ ] STREAM CONNECTED 27804 @/tmp/dbus-EvBU16isPp
unix 3 [ ] STREAM CONNECTED 27806 @/tmp/ibus/dbus-HdPg5eVU
sudo lsof -i -n -P +c 0 | grep ':80\|:443'
输出:
asad@asad-HP-ProBook-4530s:~$ sudo lsof -i -n -P +c 0 | grep ':80\|:443'
[sudo] password for asad:
chrome 3333 asad 166u IPv4 169400 0t0 UDP 10.99.2.62:52109->216.58.208.78:443
chrome 3333 asad 178u IPv4 169585 0t0 TCP 10.99.2.62:50478->151.101.193.69:443 (ESTABLISHED)
chrome 3333 asad 198u IPv4 162437 0t0 TCP 10.99.2.62:57394->151.101.113.147:443 (ESTABLISHED)
chrome 3333 asad 225u IPv4 171167 0t0 TCP 10.99.2.62:39238->104.16.108.18:443 (ESTABLISHED)
chrome 3333 asad 253u IPv4 171168 0t0 TCP 10.99.2.62:39240->104.16.108.18:443 (CLOSE_WAIT)
chrome 3333 asad 260u IPv4 171157 0t0 TCP 10.99.2.62:50480->151.101.193.69:443 (ESTABLISHED)
chrome 3333 asad 262u IPv4 168483 0t0 UDP 10.99.2.62:59052->216.58.208.66:443
chrome 3333 asad 263u IPv4 169398 0t0 UDP 10.99.2.62:47762->216.58.208.68:443
chrome 3333 asad 270u IPv4 170224 0t0 UDP 10.99.2.62:41851->216.58.208.78:443
chrome 3333 asad 271u IPv4 168485 0t0 TCP 10.99.2.62:35004->23.58.0.61:443 (ESTABLISHED)
chrome 3333 asad 272u IPv4 169426 0t0 TCP 10.99.2.62:56116->192.0.73.2:443 (ESTABLISHED)
chrome 3333 asad 287u IPv4 161862 0t0 TCP 10.99.2.62:38618->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 288u IPv4 131203 0t0 TCP 10.99.2.62:37862->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 300u IPv4 171145 0t0 TCP 10.99.2.62:38814->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 305u IPv4 170154 0t0 TCP 10.99.2.62:39516->23.57.249.169:443 (ESTABLISHED)
chrome 3333 asad 308u IPv4 168478 0t0 TCP 10.99.2.62:35000->23.58.0.61:443 (ESTABLISHED)
chrome 3333 asad 311u IPv4 129805 0t0 TCP 10.99.2.62:37858->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 313u IPv4 128964 0t0 TCP 10.99.2.62:37854->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 324u IPv4 85748 0t0 TCP 10.99.2.62:48908->151.101.65.69:443 (ESTABLISHED)
chrome 3333 asad 335u IPv4 131349 0t0 TCP 10.99.2.62:37868->198.252.206.25:443 (ESTABLISHED)
chrome 3333 asad 337u IPv4 169446 0t0 UDP 10.99.2.62:33691->216.58.210.66:443
chrome 3333 asad 341u IPv4 169448 0t0 UDP 10.99.2.62:38019->216.58.210.66:443
apache2 3679 root 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
apache2 3682 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
apache2 3683 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
apache2 3684 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
apache2 3685 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
apache2 3686 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
答案1
首先,确保你的/etc/apache2/ports.conf
包含行Listen 80
其次,请确保您已使用 启用了您的配置sudo a2ensite yoursite.name
。
第三,确保已禁用默认虚拟主机sudo a2dissite 000-default
还要添加您的 documentroot 目录的选项,例如:
<Directory /var/www/html/ednet/public/ >
Require all granted
AllowOverride All
Options Indexes
</Directory>
然后,使用重新启动 apachesudo service apache2 restart
并尝试使用浏览器访问虚拟主机。
答案2
apache2 3686 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
tcp6 0 0 :::80 :::* LISTEN
由于某种原因,Apache 显然只监听 IPv6。
更改/etc/hosts
为 IPv6:
127.0.0.1 ednet.dev
到
::1 ednet.dev
这将使您能够使用 IPv6 来访问该名称。
答案3
您的 apache 显然正在监听 IPv6,要测试它,您可以执行以下操作:
wget http://[::1]/ -O /dev/null
您将收到200 Ok
回复
要使 apache 仅监听 IPv4 地址,请添加:
Listen 0.0.0.0:80
Listen 192.0.2.1:80
答案4
我不知道问题是什么,但卸载整个 LAMP 堆栈并重新安装后问题就解决了。