[macOS Catalina] New Hugo site: localhost:1313 fails to open but 127.0.0.1:1313 works

Hello there :slight_smile:

THE SITUATION

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.

How do make localhost:1313 work?

I look forward to hearing from you :slight_smile:

Cheers,
-Alex

This appears to be more of a Catalina issue than a Hugo one:

https://discussions.apple.com/docs/DOC-250001766

https://mallinson.ca/posts/7/local-web-development-with-mac-os-catalina

Additionally, you could try:

hugo server -D --baseURL "http://alexanders-Mac-mini.local"

2 Likes

Thank you @b_rad.

Using…

hugo server -D --baseURL "http://alexanders-Mac-mini.local"

…actually does solve my problem with the link to the dummy post.

That localhost:1313 doesn’t work is something I can happily ignore for now.

Thanks a lot! :slight_smile:

You’re welcome, happy to try to help.

1 Like

I’m on the newest version of Catalina and localhost works great on both my MacBooks.

2 Likes

That’s good to know.

Then it maybe is not a Catalina issue.

Hm…?

What does your /etc/hosts look like?

This is how my /etc/hosts file looks like:

##
# 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

Is it alright?

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

1 Like

I tried…

hugo server --bind 0.0.0.0

and the output was:

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 :slight_smile:

Thanks for your effort. I appreciate it @b_rad!

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.

Just a guess…

1 Like

Thanks, Quentin.

So many good ideas!

I tried:

hugo server --bind ::1

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.

Thanks so much for all your effort :slight_smile: