A few days ago I set up Hugo on my local machine (Mac mini running Catalina). I followed the quick-start guide: Quick start | Hugo, and I also created the dummy post called „My First Post”.
When I start the server using…
hugo server -D
…no error shows and (among others) I also see this standard message…
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
THE PROBLEM
When I entered localhost:1313 the browser said it cannot open the site.
Then I entered 127.0.0.1:1313 and it worked.
That was a good step forward.
But I wanted to get localhost:1313 working.
So, I tried…
sudo apachectl configtest
…and in the response, I saw Alexanders-Mac-mini.local.
So I entered alexanders-Mac-mini.local:1313 in the browser and it worked too.
MY QUESTION
Ok, you could say…
If alexanders-Mac-mini.local:1313 and 127.0.0.1:1313 work, isn’t that good enough for you?
It would be.
But the problem is the link to the dummy post which is: http://localhost:1313/posts/my-first-post/. If I click the link, the browser (of course) cannot open it because it’s a localhost:1313 URL.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
Yes, this looks fine, however it does seem strange that you mention localhost isn’t working. Possibly you are using a virtual interface or there is another issue.
Can you try with hugo server --bind 0.0.0.0 and see if that forces localhost to work? If not, maybe also try specifying a different port with --port
Web Server is available at http://localhost:1313/public/ (bind address 0.0.0.0)
I tried to open both http://localhost:1313/public/ and 0.0.0.0 but the page didn’t load (Safari couldn’t make a connection). But weirdly, using Chrome I was able to open 0.0.0.0 getting an It works! as feedback in the browser, but opening http://localhost:1313/public/ didn’t work neither in Chrome.
I also tried hugo server --port 1234 and the results were:
http://localhost:1313/public/ opened neither in Safari nor in Chrome
127.0.0.1 opened both in Safari and Chrome and both showing It works!
So for me, it’s fine how it is. I can work with hugo server -D --baseURL "http://alexanders-Mac-mini.local". Of course, I would like localhost to work but I don’t want to spend much more time on this small detail and dedicate more time on the actual development
Quick guess (not having Catalina machine to try). Could it be that the browser is using the IPv6 address (::1) for localhost by preference, and hugo is only binding to the IPv4 address?
You could try hugo server --bind ::1 and see if localhost works then?
If I do that bind on my (older) machine, I can access the site as http://[::1]:1313 but not as http://127.0.0.1:1313.
and tried to open both http://localhost:1313/public/ and http://[::1]:1313 in Safari and Chrome.
Result for http://localhost:1313/public/ (and for http://127.0.0.1:1313):
Browser can’t open page.
Result for http://[::1]:1313:
404 page not found
Conclusion (for now)
@b_rad’s solution (see above) is the only thing that works for me.
I’ll maybe consider using https://sitejs.org because I see that Aral Balkan has been using it successfully with his own blog and his foundation with Laura.