Can't reach Discourse server in VM from Host

Hello there! I’ve successfully installed Discourse in an Ubuntu 18.04 virtual machine (using VMware Workstation 15 Player) following the guide. Access to http://localhost:3000/ from inside the VM goes well, but I can’t reach it from my Windows 10 host system. The VM network is configured in bridged mode, and for executing the rails server I’m running:

bundle exec rails server --binding=0.0.0.0

However, when I go to http://192.168.0.172:3000/ from my host machine, I get a connection refused error. I’ve tried setting up a simple Python HTTP server inside the VM:

python3 -m http.server 3000

And I can effectively reach it from my host machine, so I think this is Discourse-specific. Am I missing something?

Thanks in advance!

Hello @Hugo_Lol

You might find it helpful to review how to set up port forwarding between a host and a VM, for example:

Another example:

Maybe you can use these examples to give you an idea how to get started solving this?

Hope this helps.

1 Like

Hi @neounix, thanks for the reply. I’ve already configured the VM network in bridged mode, and I can reach it from the outside using a simple Python HTTP server that listens in the same port (3000) and address (0.0.0.0), but for some reason it doesn’t work with the Discourse server… :thinking:

Any ideas?

1 Like

Hey @Hugo_Lol,

You are welcome.

I am not a Windows user so I cannot be of much further help, sorry about that!

The best suggestion I have is to look for clues in the various Discourse logfiles in /var/log.

The problem here is that the --binding option is completely ignored. I tried your command locally and I spotted this line in the output (the output is very noisy so it’s very easy to miss this line):

I, [2020-06-08T17:26:55.938086 #21001]  INFO -- : listening on addr=127.0.0.1:3000 fd=15

Reading through our config/unicorn.conf.rb, to make the server listen to 0.0.0.0 you’ll need to set the UNICORN_BIND_ALL=1 environment variable. So this should work: UNICORN_BIND_ALL=1 bundle exec rails server.

Alternatively, you can use the bin/unicorn script which does accept a --host option that you can use to bind to 0.0.0.0.

9 Likes

That did the trick! It’s working now. Thank you both a lot. :clap:

6 Likes

Thanks, this saved me some headache.
I wonder if you can update official user guides to include this instead of non working solution with bundle exec rails server -b 0.0.0.0.
I saw it all over the internet and couldn’t imagine that it would not work

Absolutely, you can do so yourself! it is a wiki :+1:t3:

1 Like

Thanks bro! Had the same problem, this fixed it!

1 Like