BrowserSync with Vagrant, Zurb Foundation, Nginx, Gulp - nginx

I seem to be close after a couple of days deep into this setup but still can't get BrowserSync to use Nginx as the server on the Vagrant Ubuntu 14.04 with Nginx guest and view the html on my MacBook Pro host. However, on http://localhost:3001/ on my Mac Chrome browser I can view a BrowserSync page with settings and such. Therefore I suspect I'm doing something right, but probably not much.
I expect to see the Foundation splash page but I get "This site can’t be reached". Before I modify the gulpfile I can view the splash page with localhost:8079, the usual setup, so Foundation is working correctly.
I've tried localhost: 3000, 3001, and 3002 and those ports with the Vagrant IP 10.0.2.15 and 127.0.0.1 and 0.0.0.0. Anyone have a setup that works with this stack? I couldn't find a discussion anywhere with this setup.
The relevant parts of my gulpfile. I'm modifying what Foundation for Apps sets up.
var browserSync = require('browser-sync').create();
I got this code off a forum. I also tried other similar configs. I've commented out the Foundation server setup because I want to develop with Nginx. My limited understanding it that if I use the "server" in BrowserSync that I'll get a little dev server like Foundation's.
gulp.task('browser-sync', function() {
browserSync.init({
proxy: 'localhost:3002'
});
});
At the bottom of the Gulpfile we do the watch thingy.
gulp.task('default', ['browser-sync'], function () {
// Watch Sass
gulp.watch(['./client/assets/scss/**/*', './scss/**/*'], ['sass']);
...
After running "foundation watch" I get this:
[BS] Proxying: http://localhost:3002
[BS] Access URLs:
----------------------------------
Local: http://localhost:3000
External: http://10.0.2.15:3000
My Vagrantfile has port forwarding. The first three work as expected.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", host: 8080, guest: 80
config.vm.network "forwarded_port", host: 8079, guest: 8079
config.vm.network "forwarded_port", host: 1337, guest: 1337
config.vm.network "forwarded_port", host: 3000, guest: 3000
config.vm.network "forwarded_port", host: 3001, guest: 3001
config.vm.network "forwarded_port", host: 3002, guest: 3002
config.vm.host_name = "sails"
config.vm.provision :shell, path: ".provision/bootstrap.sh"
config.vm.provision "file", source: "~/.gitconfig", destination: "~/.gitconfig"
This URL also works to see the Foundation splash page which is served by Nginx. I haven't studied Nginx yet but one step at a time. I'll have to figure out how to setup the servers for static and dynamic files.
Appreciate help of course. I put my Vagrant setup files here if anyone with this stack wants a shortcut to a great dev environment: https://github.com/svstartuplab/Vagrant-Foundation-Sails-Nginx

Related

vagrant how to access web server (nginx) with public ip

I have tried doing it like this in my vagrantfile
config.vm.network "private_network", ip : "192.168.33.15"
so when I start my box, I could access nginx through my browser 'locally'.
what I want is to access it using public ip. I have tried this, (found in documentation)
config.vm.network "public_network", ip: "202.137.x.x", netmask: "255.255.x.x"
config.vm.provision "shell",
run: "always",
inline: "route add default gw 202.137.x.x"
config.vm.provision "shell",
run: "always",
inline: "eval `route -n | awk '{ if ($8 ==\"eth0\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
this still doesn't work. any ideas?
*edit
I've also tried port forwarding,
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "202.137.x.x"
I have to do this: 202.137.x.x:8080, I wanted to access without the port. Also, host port cannot be < 1024, so I cannot put port 80..
I've tried doing port forwarding in windows (host), so this is how I solved it..
netsh interface portproxy add v4tov4 listenport=80 listenaddress=202.137.x.x connectport=8080 connectaddress=202.137.x.x
This forwards any requests to the host on port 80 to port 8080 on the host.
So, the port forwarding flow becomes:
host:80 => host:8080 => guest:80
source here

VagrantFile config.vm.network

When my VagrantFile has
config.vm.network :forwarded_port, guest: 9000, host: 9000
I execute the vagrant up statement
Will be displayed.
I thought it was because the post was taken, and I execute netstat -aon , and there is no corresponding port.
If I delete the statement on config.vm.network, Vagrant can be opened normally.
Can someone help me solve it?
It appears to be an issue with the new vagrant 1.9.3 (see https://github.com/mitchellh/vagrant/issues/8395)
you can fix it by adding the host_ip: "127.0.0.1" parameter for each of the "forwarded_port" network configuration.
config.vm.network :forwarded_port, guest: 9000, host: 9000, host_ip: "127.0.0.1"

Vagrant port forwarding stops working after a while

I am using an ubuntu provisioned vagrant vm to sun a service. Here is the vagrant file
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.provision "file", source: "/opt/artifactory-pro-4.11.1", destination: "/opt/"
config.vm.network "forwarded_port", guest: 80, host: 70
config.vm.network "forwarded_port", guest: 8081, host: 7081
end
I then try to access the service at "localhost:7081" I can access it for sometme but then it becomes unavailable. I've tried to configure the host_ip as
host_ip = 127.0.0.1 and host_ip = 0.0.0.0
But the problem still persists
I tried destroying the VM and running the service on different ports but no luck

Vagrant network

I have a vagrant box:
Vagrant.configure(2) do |config|
config.vm.box = "parallels/centos-7.1"
config.vm.box_check_update = false
config.vm.hostname = "vagranthost"
config.vm.network "forwarded_port", guest: 80, host: 8080
end
Guest machine gets ip address 10.211.55.17. Sometimes last number changes, but that doesn't matter.
Host machine is always 10.211.55.2.
There is nginx inside the box:
server {
listen 80;
server_name mill.localhost;
...
}
And simple php script: echo $_SERVER['REMOTE_ADDR'];
So, I'm accessing this box from my host machine.
If I access that script from the browser as http://mill.localhost:8080/, I'm getting 10.211.55.1.
I can make curl -H "Host:mill.localhost" http://10.211.55.17/, and I'll get excpected result: 10.211.55.2.
So, the questions are: why is this happening? What is that node 10.211.55.1 in the network? Is there any way, I can get 10.211.55.2 from the browser (http://mill.localhost:8080/)?

connection refused from host machine

I am using vagrant with virtualbox as provider. Within my guest system I have nginx installed and configured.
nginx is serving some static files from a folder and exposing them on port 80. That works fine. If I call curl localhost within the guest machine I get the answer I was supposed to receive.
I have a very simple vagrantfile, which you can see below. I forward port 80 to port 8080, but from the host machine I cant access that page via localhost:8080.
I already disabled the firewall in the guest machine without any success.
Vagrant.configure("2") do |config|
# VirtualBox Settings: Give it a little bit more memory
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "768"]
end
# Base Image: CentOS 7.0 x86_64
config.vm.box = "jayunit100/centos7"
# Use Vagrant's default insecure key (~/.vagrant.d/insecure_private_key)
config.ssh.insert_key = false
# Add port forwarding for node-inspector
config.vm.network :forwarded_port, guest: 80, host: 8080 # node-inspector
# Map project directory
config.vm.synced_folder ".", "/server/"
# Provisioning Shell Script
config.vm.provision :shell, :path => "vagrant-setup/base.sh"
end
If I call curl -v 'http://localhost:8080' from the host system I get told that the connection got refused. Any idea what I could do?
I had to disable my firewall on the host machine with iptables -F

Resources