3

note this is NOT related to Apache and I'm not looking for Apache-centered answers.

I am using the Hugo static site generator to create sites and trying to test on a MacBook running Sierra.

I am able to start the server with

hugo server -Dw

And the server starts on localhost:1313, however when I try to access that URL I get a 404. 127.0.0.1:1313 works, but then all of the links fail as they try to resolve back to localhost.

I was able to access by enabling a domain name on my router (foo.home) and then I can open the main page with localhost.foo.home:1313, but all of the Hugo links still try to use localhost:1313.

So, two questions:

  1. Can I change the behavior of Hugo to use 127.0.0.1? I tried changing the baseURL in config.toml to localhost, 127.0.0.1 and the foo.home domains, but that didn't seem to do anything.
  2. Or, can I change the /etc/hosts file to resolve localhost?

Right now /etc/hosts has four entries - I am wondering if I can add another entry for 127.0.0.1 localhost but there's a warning about not making changes as it will break configuration of the loopback interface.

127.0.0.1       localhostw
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0     localhost
  • 1
    localhost is just the hostname of the IP 127.0.0.1; they are the same thing. The problem that I am seeing is your first link in your etc/hosts file - you have a trailing w. It should be localhost – Allan Aug 27 '17 at 21:00
  • Thanks - I thought that was added by macos for some reason and that's why there's the note to not change it. Should I try renaming from localhostw to localhost? I just don't want to blow up my boot process. – lonstar Aug 27 '17 at 21:42
  • 1
    Go ahead and change it. It can't blow up your system, it can only give you the wrong address for another host. – Allan Aug 27 '17 at 22:01
  • That did it. Thanks for your help.Hopefully this will help someone else who has the same issue. If you post "check your /etc/hosts file and make sure 127.0.0.1 localhost is present" as an answer, I'll accept it. – lonstar Aug 27 '17 at 22:05
  • 1
    @lonstar It looks to me like there's still a problem. "localhost" resolves to both the local IP version 4 address (127.0.0.1) and the local IP version 6 addresses (::1 and fe80::1%lo0). Even with the typo ("localhostw"), the IPv6 addresses should still work. Unless, that is, hugo is for some reason failing to listen for IPv6 connections; if this is the case, you can still have trouble connecting via localhost. Try netstat -an | grep '[.]80 ' and see if it lists listeners on the IPv6 addresses as well as IPv4. – Gordon Davisson Aug 27 '17 at 22:36
3

The key to this error was the following:

127.0.0.1:1313 works, but then all of the links fail as they try to resolve back to localhost.

That gave the hint - accessing via IP works but not via hostname. Thankfully, the /etc/hosts file was also included for examination. In it we see the following line (1st line):

127.0.0.1       localhostw

The trailing "w" at the end of the hostname localhost will cause the error. In effect, localhost wasn't defined, but localhostw was.

Removing the "w" will solve the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .