http://localhost not working

11,984

Solution 1

The reason a ping responds with that address but browsing fails is because ping is using IPv6 automatically, and the system is resolving localhost with the IPv6 address, which your webserver apparently isn't serving on. If you add an entry to the Windows\System32\drivers\etc\hosts file with this:

127.0.0.1       localhost

then it should force the system to resolve localhost as the IPv4 address instead.

Another "fix" includes disabling IPv6, as Tie-fighter suggests, but really the "best" solution would be to make your webserver work when using IPv6 ("best" being a very subjective thing in this case).

Good luck,

--jed

Solution 2

Is there a weird VirtualServer for localhost that's different from the default one configured? When you use "localhost", it can get matched by a ServerAlias or ServerName configuration. If that configuration is bad, (eg: wrong wwwroot), then it won't work with the localhost, but might with an IP.

So check your httpd.conf for localhost. Or add ServerAlias localhost to the VirtualServer that's working properly.


--Christopher Karel

Solution 3

::1 is the IPv6 version of localhost, so it is working.

Localhost always translates to the loopback IP address 127.0.0.1 in IPv4, or ::1 in IPv6.

Share:
11,984

Related videos on Youtube

kapitanluffy
Author by

kapitanluffy

Updated on September 17, 2022

Comments

  • kapitanluffy
    kapitanluffy over 1 year

    i am using xampp 1.7.1 PHP 5.2.9

    pinged localhost on cmd and it showed

    Reply from ::1: time<1ms
    Reply from ::1: time<1ms
    Reply from ::1: time<1ms
    Reply from ::1: time<1ms
    

    hosts file has

    127.0.0.1 localhost
    127.0.0.1 localhost.com
    127.0.0.1 www.localhost.com
    

    any other ideas? http://127.0.0.1 and http://ipaddress works

    • Anna Reed
      Anna Reed over 13 years
      Please do elaborate what your problem is/what you are trying to do.
    • Admin
      Admin over 13 years
      What is it you are trying to accomplish?
    • mmattax
      mmattax over 13 years
      The obvious question: Are you sure that Apache is running?
    • kapitanluffy
      kapitanluffy over 13 years
      @Jim mm..trying to browse localhost on a browser?
    • bitmask
      bitmask over 13 years
      Does the error log (of the apache) show anything if you access http://localhost?
    • kapitanluffy
      kapitanluffy over 13 years
      @bit nothing actually i viewed the error.log file and these are the last 5 ones i saw [Sun Aug 15 18:30:17 2010] [notice] Digest: generating secret for digest authentication ... [Sun Aug 15 18:30:17 2010] [notice] Digest: done [Sun Aug 15 18:30:19 2010] [notice] Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 configured -- resuming normal operations [Sun Aug 15 18:30:19 2010] [notice] Server built: Dec 10 2008 00:10:06 [Sun Aug 15 18:30:19 2010] [notice] Parent: Created child process 2652
    • kapitanluffy
      kapitanluffy over 13 years
      i just uninstalled ipv6 from my computer. i will try what lain said..although i am sure i already did this.but he said that it works on him so ill try it again HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\‌​Parameters\DisabledC‌​omponents DWORD value 0x20 thanks for everyones help :)
  • Admin
    Admin over 13 years
    If the downvoter would like to leave a reason as to why this is not useful, I'll be happy to change it.
  • kapitanluffy
    kapitanluffy over 13 years
    i think because most people around here knows that? xD well its still a bad idea to down vote someone xD
  • user9517
    user9517 over 13 years
    It's probably not getting anywhere near the router, he's using the loopback interface.
  • kapitanluffy
    kapitanluffy over 13 years
    i ticked Microsoft TCP/IP Version 6 in the Network Connections>Local Area Connection>Properties..the ping still looks the same
  • tatan restrepo
    tatan restrepo over 13 years
    i have a world of warcraft server and i had that issue, enter on this webpage canyouseeme.org and try with the diferent ports
  • kapitanluffy
    kapitanluffy over 13 years
    actually there's no ::1 localhost..what i stated above are everything i have on the hosts file
  • kapitanluffy
    kapitanluffy over 13 years
    so it means my apache doesnt support ipv6? so maybe ill go for disablibg the ipv6..how can i do that?like what i commented on tie fighter..i ticked TCP/IP version 6 in the properties of my Local Area Connection ..nothing happened..i guess im in the wrong way xD
  • user9517
    user9517 over 13 years
    I updated my answer to reflect reality. I did this and my system now resolves localhost to 127.0.0.1 and not ::1
  • YwH
    YwH over 13 years
    I haven't done much apache configuration lately, so the following is mere speculation, but I'd guess that it probably does support IPv6, it likely just needs to be enabled. You could see if anything is currently listening on port 80 for IPv6 by doing a "netstat -an" from the command line and looking for an entry similar to this one: "TCP [::]:80 [::]:0 LISTENING".
  • bitmask
    bitmask over 13 years
    I think that does not answer the question, because the problem is not in the result of the ping, but probably that entering http://localhost in the browser does not get one the same page as http://127.0.0.1. However, this is pure speculation as the OP did not state the actual problem.
  • kapitanluffy
    kapitanluffy over 13 years
    i edited it with the value 20..the value shown is..0x0000020 it doesn't do anything..i don't know the exact value of 0x20..ill try inputting 20000000
  • kapitanluffy
    kapitanluffy over 13 years
    my problem is..when i tried browsing the localhost on my browser it says connection was reset. i tried 127 and it works..also for my ip
  • kapitanluffy
    kapitanluffy over 13 years
    the service listening on port 80 is apache it self..like i said..127 and my ip works..but not for localhost
  • kapitanluffy
    kapitanluffy over 13 years
    uhm where exactly should i add that? sorry for being so noobish here xD
  • kapitanluffy
    kapitanluffy over 13 years
    i have three actually.. TCP [::]:135 [::]:0 LISTENING 0 TCP [::]:8080 [::]:0 LISTENING 0 TCP [::1]:30606 [::]:0 LISTENING 0 ..so how can i enable ipv6?
  • Admin
    Admin over 13 years
    I'm with Iain on this. 127 is loopback and it won't leave the machine.
  • r00tcreat0r
    r00tcreat0r over 13 years
    DWORD is a hex value, so 20 was correct. 20000000 won't help at all.
  • user9517
    user9517 over 13 years
    @kapitanlufy: 0x20 is common notation for a hexadecimal value. After you have created the key double click on it and you'll get a pop up to edit the DWORD (32 bit) value. Ensure that the Hexadecimal radio button is checked and enter 20 in the value data: box. Click OK.