Apache Virtual host not working
Andrew Henderson
I followed this tutorial to set up Apache virtual host, but browser is unable to serve the homepage.
Here is my .conf file
<VirtualHost *:80> ServerAdmin ServerName ednet.dev ServerAlias DocumentRoot /var/www/html/ednet/public ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>my host file
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-allroutersbut when i try to open ednet.dev in browser it gives error
This site can’t be reached
ednet.dev refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSEDsudo netstat -na | grep 80 Output
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-HdPg5eVUsudo lsof -i -n -P +c 0 | grep ':80\|:443' output:
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) 6 4 Answers
At first, be sure that your /etc/apache2/ports.conf contain line Listen 80
At second, be sure that you have enabled your config using sudo a2ensite yoursite.name.
At third, be sure that you have disabled default virtualhost sudo a2dissite 000-default
Also add options for your documentroot directory, for example:
<Directory /var/www/html/ednet/public/ > Require all granted AllowOverride All Options Indexes
</Directory>Then, restart apache using sudo service apache2 restart and try to get access to virtualhost using the browser.
apache2 3686 www-data 4u IPv6 153144 0t0 TCP *:80 (LISTEN)
tcp6 0 0 :::80 :::* LISTEN Apache obviously only listens on IPv6 for some reason.
Change /etc/hosts to IPv6:
127.0.0.1 ednet.devto
::1 ednet.devThis will enable you to use IPv6 for reaching the name.
You apache is obviously listening to IPv6, to test it you can do:
wget -O /dev/nulland you will get 200 Ok as response
to make apache listen to only IPv4 addresses you add:
Listen 0.0.0.0:80 Listen 192.0.2.1:80source:
3I don't know what was the problem but after uninstalling whole LAMP stack and reinstalling it again solve the problem.