Vagrant : Connect from client to local https site - vagrant

I am working on a chef project which is running in Vagrant. I have installed chef server on my local machine and I need to connect it from vagrant instance. I am getting a connection refused. I have added port-forwarding, but vagrant wont let me forward port-443 as it's already occupied. My chef server is running on https i.e port-443.
Error log :
[2019-05-03T10:21:00+00:00] INFO: Client key /etc/chef/client.pem is not present - registering
[2019-05-03T10:21:00+00:00] ERROR: Connection refused connecting to https://my-system-product-name/organizations/internetdevelopment/clients, retry 1/5
[2019-05-03T10:21:05+00:00] ERROR: Connection refused connecting to https://my-system-product-name/organizations/internetdevelopment/clients, retry 2/5
VagrantFile :
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 443, host: 8443
config.vm.network "forwarded_port", guest: 80, host: 8080

i would offer you to assign a static ip address to your vagrant virtual machine (vm) rather than use a port forwarding.
You can also specify a static IP address for the machine. This lets you access the Vagrant managed machine using a static, known IP. The Vagrantfile for a static IP looks like this:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
It is up to the users to make sure that the static IP does not collide with any other machines on the same network.
While you can choose any IP you would like, you should use an IP from the reserved private address space. These IPs are guaranteed to never be publicly routable, and most routers actually block traffic from going to them from the outside world.

Related

CouchDB on Vagrant VM (Scotch box)

I'm trying to set up CouchDB (and ultimately use PouchDB) on a Scotch Box VM. The VM runs fine, and includes port forwarding for port 5849 by including the code below:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box-pro"
config.vm.hostname = "scotchbox"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 5984, host: 5984
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "private_network", ip: "192.168.33.10"
The VM runs fine. localhost:8080 will load the PHP home page, and localhost:3000 will load a node script if I have the node server running, but localhost:5984 only returns an empty response when loaded from the browser or from the host machine command line using curl curl: (52) Empty reply from server.
When I have used vagrant ssh to access the VM, I can use curl localhost:5984 to obtain {"couchdb":"Welcome","uuid":"9cabeb8f66947adabe9443594aa7f69c","version":"1.6.0","vendor":{"version":"15.10","name":"Ubuntu"}} as expected.
Here is the guide I've been referring to: https://pouchdb.com/guides/setup-couchdb.html
Additional info: When I go to 192.168.33.10:5984 (instead of using the localhost port forwarding), the result is a refused connection.
Any suggestions as to what my issue might be? I had thought it was a forwarding issue, but the ports 8080 and 3000 work fine, and going to the IP:5984 doesn't work so it makes me wonder. I also thought maybe the service isn't running, but doing ssh on the VM and running curl seems to indicate that it is in fact running.
Thanks!
By default CouchDB bound to a localhost address 127.0.0.1 and you need to re-bind it to 0.0.0.0 to get it accessible from outside of Vagrant box. To do that you need to change parameter bind_address in [httpd] section of default.ini config file or add the same as override in local.ini config file.

How configure Vagrant so doesnt block forwarded ports on host when on private network

I want a vagrant VM to behave like a box not hosted on my host machine.
I want to be able to do
curl <vagrant private ip> #nginx on the vm
and have that work from the host machine
curl localhost #e.g. iis
and have that work from the host machine
but it seems it's not possible as when you do port forwarding it always occupies the host port too on the loopback/or IP and you cant restrict it to just the private IP of the VM, basically, you cant have the VM running and start iis.
If that is the case ok, that's that.
currently, my Vagrant file has
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "private_network", ip: "192.168.33.11
I know the forwarded_port has guest_ip and host_ip settings but I didn't find they did anything when I tried to set to the private network IP.
Any suggestion of easy workaround also welcome.

Vagrant: port forwarding is working oddly

I've got this in my Vagrantfile:
web.vm.network "private_network", ip: "192.168.33.20"
web.vm.network "forwarded_port", guest: 80, host: 8080
but on my Mac Host I'm able to access the web VM using 192.168.33.20:80 but NOT 192.168.33.20:8080.
Why is this not working as expected?
vagrant Port forwarding is used if you dont have static IP and you want to reach a specific port for a process bound to this specific port running on the VM, so you will access it using http://localhost:8080 and it will forward to port 80 on the VM.
When you have a static IP, you reach directly the network interface to this VM so it tries to connect you on the port 8080 directly in the VM, if you dont have anything running there, it wont show up.
Rules: if you use static IP (wether private or public network) you dont need port forwarding

How to forward a port to vagrant guest if this port already listened by host machine

For example I have an app which run vagrant machines dynamically and expect some info from them will be sent through http to specific host machine port. So, my app listening specified port (http server) and I can't forward that port:
C:\node-vagrant-test-task>vagrant reload
==> default: Clearing any previously set forwarded ports... Vagrant cannot forward the specified ports on this VM, since they would
collide with some other application that is already listening on these
ports. The forwarded port to 8080 is already in use on the host
machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 8080, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.
If you do not want to mess with forwarding port, the best is to use a static IP for the guest
you can do either private or public networks with a static IP
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
or
Vagrant.configure("2") do |config|
config.vm.network "public_network", ip: "192.168.50.4"
end
so you dont need to forward the 8080 port and can access your app directly on http://192.168.50.4:8080
If you need to then access the host machine for this guest, you can access it via 192.168.50.1

Vagrant port forwarding not working. Cups not accesible from host

So I'm working with vagrant and I'm trying to use it as a printing server. I installed cups.
Internally everything works just fine. I can even make a quick curl to my localhost:631 (cups port inside my vagrant) and there's everything.
The thing is I cant access it in any way I try from the host machine.
Obviously I forwarded the port and I've tried with several ports. I've also tried with Debian squeeze and Ubuntu 12.04. Here is my current Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "guruDebian"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :forwarded_port, guest: 631, host: 6363 ## HERE IS CUPS
end
Any ideas?
I think what you will find is that the default cups config file is locked down to only work from localhost for security reasons.
Inside your Vagrant VM open the /etc/cups/cupsd.conf file and change the following line:
Listen localhost:631
to
Listen 0.0.0.0:631
That should allow you to connect from any host.
Have you tried accessing port 8080 of guest to your host? if no, and the services inside guest are running. then its a firewall issue in guest.
Try to turn firewall temporarily
service iptables off
then try to access it again from host.

Resources