If you are using Virtualbox, by default it will emulate the network using NAT. This is the simplest way to provide network access to the virtual network adapter inside the virtual machine, but it has the side effect that you can't actually connect to the services on the virtual machine from the host system.
You would need to change the mode of network emulation in the virtual machine from NAT to "bridged".
Note that this is slightly more complex from your host operating system's point of view as it has to get low level access to your host's network adapter at the packet level. This involves installing a special driver, particularly on Windows hosts. Essentially your network adapter on the host will need to start behaving in a way like multiple network adapters. This can sometimes (but not in normal situations) conflict with your outer network.
Instead of "bridged", you could also use "host-only networking" which avoids all the above potential issues but then your guest OS won't have access to the wider network (eg the Internet).
If you're using something other than Virtualbox, the issues will probably be the same, but the way of fixing it may not be.