holandes22 / rafee

1 stars 1 forks source link

Nginx: Fix error about port already used #33

Open holandes22 opened 9 years ago

holandes22 commented 9 years ago

Server works, but spam the log with errors like [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in use)

apparently the workers raise this error after the main process was started

tzurE commented 9 years ago

So, after a small research - This issue seems exactly like this one - only using chef instead of ansible: http://stackoverflow.com/questions/25815984/chef-supervisor-service-conflict-with-already-serviced-programs-nginx-in-thi

I've checked the VM, and saw the same errors in the supervisor logs at this location(it's spamming it): /var/log/supervisord/nginx-stderr---supervisor-VjzSuO.log

nginx: [emerg] bind() to [::]:8000 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:8000 failed (98: Address already in use)

It seems to be caused because of the way we handle deployment. so either we change it with this deployment(I'm trying to understand everything the supervisor does) but if it's just a development deployment - won't the production will be a different kind of deployment? so this bug might be different in production. what to do? continue reading on the deployment and try changing some stuff? create a new playbook that handles nginx differently?

holandes22 commented 9 years ago

Well, the idea of Vagrant and using the same provision script for dev and prod environments is to have no differences between them. So if it happens in the dev env, assume it will be the same in production (will use the same distro, same ports, etc)

Problem here is that nginx is saying that cannot binds to that port. This means mainly that the port is used. I run netstat and only nginx process is using it, but probably missed something.

So, we need to find which process is using that port and kill it. Another possibility is that there is an error in the nginx conf, meaning is not properly configured

tzurE commented 9 years ago

I checked the nginx.conf, but will do so again. meanwhile I found out that if I log into the VM and kill the process that listens on port 8000 manually using: sudo fuser -k 8000/tcp (need to run it twice) and than I start nginx, the spamming errors stop (both nginx logs and supervisor logs) and nginx listens to that port and has no trouble binding.