I have a rails application deployed through capistrano on an aws ec2 instance and have passenger nginx installed on the server as well. Whenever I try and access my application using the DNS or the public IP provided, all I get is the browser loading for a while ending with no response, not even an error page from nginx. Here are my nginx config (/etc/nginx/sites-enabled/default)
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name <public ip>;
passenger_enabled on;
rails_env production;
root /home/ubuntu/myapp/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Upon running the command "sudo nginx" this is the response I get:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
I have spent hours searching for a solution, but haven't been able to access my app. Any help even guidance towards the right direction would be hugely appreciated. If anymore information is needed please let me know.
EDIT
Inside the error.log this is what I have been getting:
[ 2015-07-21 12:59:54.2681 21794/7eff039a4700 age/Cor/Main.cpp:507 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) t$
[ 2015-07-21 12:59:54.2681 21794/7eff0a1747c0 age/Cor/Main.cpp:876 ]: Received command to shutdown gracefully. Waiting until all clients have di$
[ 2015-07-21 12:59:54.2682 21794/7eff031a3700 Ser/Server.h:752 ]: [ApiServer] Freed 0 spare client objects
[ 2015-07-21 12:59:54.2682 21794/7eff031a3700 Ser/Server.h:443 ]: [ApiServer] Shutdown finished
[ 2015-07-21 12:59:54.2683 21794/7eff039a4700 Ser/Server.h:752 ]: [ServerThr.1] Freed 128 spare client objects
[ 2015-07-21 12:59:54.2683 21794/7eff039a4700 Ser/Server.h:443 ]: [ServerThr.1] Shutdown finished
[ 2015-07-21 12:59:54.2688 21794/7eff0a1747c0 age/Cor/Main.cpp:942 ]: Passenger core shutdown finished
[ 2015-07-21 12:59:54.2695 21799/7fb5deb62700 age/Ust/Main.cpp:337 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) t$
[ 2015-07-21 12:59:54.2695 21799/7fb5e536d7c0 age/Ust/Main.cpp:399 ]: Received command to shutdown gracefully. Waiting until all clients have di$
[ 2015-07-21 12:59:54.2695 21799/7fb5deb62700 Ser/Server.h:752 ]: [LoggerApiServer] Freed 0 spare client objects
[ 2015-07-21 12:59:54.2696 21799/7fb5deb62700 Ser/Server.h:443 ]: [LoggerApiServer] Shutdown finished
[ 2015-07-21 12:59:54.2697 21799/7fb5e536d7c0 age/Ust/Main.cpp:424 ]: Passenger UstRouter shutdown finished
[ 2015-07-21 12:59:55.3126 21887/7f0fcdb1e7c0 age/Wat/Main.cpp:1274 ]: Starting Passenger watchdog...
[ 2015-07-21 12:59:55.3190 21890/7f1083bfc7c0 age/Cor/Main.cpp:957 ]: Starting Passenger core...
[ 2015-07-21 12:59:55.3191 21890/7f1083bfc7c0 age/Cor/Main.cpp:234 ]: Passenger core running in multi-application mode.
[ 2015-07-21 12:59:55.3288 21890/7f1083bfc7c0 age/Cor/Main.cpp:707 ]: Passenger core online, PID 21890
[ 2015-07-21 12:59:55.3356 21895/7fc7fb8a07c0 age/Ust/Main.cpp:430 ]: Starting Passenger UstRouter...
[ 2015-07-21 12:59:55.3445 21895/7fc7fb8a07c0 age/Ust/Main.cpp:311 ]: Passenger UstRouter online, PID 21895
I even tried to free the port 80: using
sudo fuser -k 80/tcp
which resulted in:
80/tcp: 22143 22146 22147 22148 22149
Does that mean that it destroyed 5 connections to the same port, which can be the issue? If yes then is there a way to just maintain one single connection to that port, the connection of the process running my application.
After this I restarted nginx and its the same result, and on typing sudo nginx I get the same response as I have posted above
EDIT 2
After much googling I found this command "sudo lsof -i:80" and here is the output it produces, if this helps then please suggest your solutions, its been quite a while since I have been stuck on this issue.
nginx 18275 root 6u IPv4 1213246 0t0 TCP *:http (LISTEN)
nginx 18276 www-data 6u IPv4 1213246 0t0 TCP *:http (LISTEN)
nginx 18277 www-data 6u IPv4 1213246 0t0 TCP *:http (LISTEN)
nginx 18278 www-data 6u IPv4 1213246 0t0 TCP *:http (LISTEN)
nginx 18279 www-data 6u IPv4 1213246 0t0 TCP *:http (LISTEN)
What I believe is that there are multiple connections running on port 80 which eventually are choking it from responding, I might be wrong but please suggest your solutions.
I have even removed the default file from /etc/nginx/sites-enabled/default , created a new config file and symlinked it as well but the issue remains the same.I have also checked my ec2 instance security group, it allows inbound traffic on port 80 from everywhere. Can there be any other issue or m I looking in the wrong direction for solutions?
running sudo netstat -tulpn | grep :80
gives the following output
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18878/nginx
Also to point out I have deployed a branch of my project's repo and not the master branch itself once its deployed and working I plan on merging the branch to master and deploy it again.
EDIT3
I have tried this from my local terminal:
telnet <public ip> 80
and this is the response I get
Trying <public ip>.
Connected <public ip>.
Escape character is '^]'.