1

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 '^]'.
  • Why ipv6only=on? – Federico Sierra Jul 21 '15 at 0:17
  • Check port 80 already used or not? – jasonz Jul 21 '15 at 1:18
  • @FedericoSierra actually m not much experienced with server deployment so I searched for some sample configurations and added this to my server configurations, should I remove it? – Zaeem Asif Jul 21 '15 at 8:18
  • @jasonz sure I will try and check that – Zaeem Asif Jul 21 '15 at 8:23
  • Try set ipv6only=off – Federico Sierra Jul 21 '15 at 11:02
0

You have a process that binds to port 80 already. Check it out via

netstat -ntp | find "80"

Once you get its PID (1234 for instance) send a signal to gracefully shutdown the process:

kill -15 1234

If it doesn't help and process is still running wait a bit then send another signal type to PID:

kill -9 1234

After this you can start Nginx again with no issues.

  • sir upon typing the command " netstat -ntp | find "80" " I get the response find: `80': No such file or directory (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) However I tried using "sudo netstat -ntp | grep "80"" as well which resulted in nothing. – Zaeem Asif Jul 21 '15 at 8:30
  • Sir I used "sudo lsof -i:80" and then used kill -15 to one by one kill all the processes I got as the result of running "sudo lsof -i:80", but as soon as I refresh the page on my browser with DNS/public IP the issue remaind as it was, on running "sudo lsof -i:80" I again got 5 processes as I did before with different process IDs – Zaeem Asif Jul 22 '15 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.