Reputation: 24478
I'm using the following Vagrantfile to install nginx. After I run vagrant up, a request to http://192.168.33.14/
returns a 404 from nginx. After I run 'vagrant reload', making a request to http://192.168.33.14/
returns the expected proxied result.
I expect that the proxy works as expected after vagrant up. I am writing the config change after running the nginx cookbook, so I suspect I need to reload nginx after writing the config file. I tried a shell provisioner running sudo /usr/sbin/nginx -s reload
, this fails with nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
.
Vagrant.configure("2") do |config|
config.vm.box = "opscode-ubuntu-14.04"
config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box"
config.omnibus.chef_version = :latest
config.vm.provision "shell", inline: "echo 'set nocp' > /home/vagrant/.vimrc"
config.vm.define "nginx" do |nginx|
nginx.vm.network "private_network", ip: "192.168.33.14"
nginx.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "nginx"
chef.json = {
:nginx => {
dir: '/etc/nginx' # this is the default value, sample only
}
}
end
nginx.vm.provision "shell",
inline: "echo -e $1 > /etc/nginx/conf.d/nginx.conf",
args: [<<-EOS
server {
listen *:80;
location ~ ^/ {
proxy_pass http://192.168.33.11:8080;
}
}
EOS
]
end
Upvotes: 0
Views: 684
Reputation: 24478
Another work-around was found, setting install_method to source:
vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "nginx"
chef.json = {
:nginx => {
install_method: "source"
}
}
end
I found the workaround here: https://github.com/miketheman/nginx/pull/223
Upvotes: 0
Reputation: 26
I was experiencing the same problem, also using Ubuntu 14.04 as the base box.
This post helped me: http://www.rollnorocks.com/2014/05/fear-and-loathing-with-chef-and-nginx/
In short, the PID location for the initial install is different to what's set in the config. The chef recipe sets the config PID (default /var/run/nginx.pid), but the initial install uses the default Ubuntu setting (/run/nginx.pid).
A quick way of resolving this problem is adding this line to an attribute file: override['nginx']['pid'] = '/run/nginx.pid'
This means the chef PID location is set to the same location that Ubuntu uses on the initial install.
A better fix would be to improve the recipe so the initial install uses a PID as set by chef - I can't find where to add that, so for now I'm using the quick fix above.
Upvotes: 1