1

I'm running Ubuntu 10.10 with three apache virtual hosts. I just followed this tutorial to set up Rails 3 on Ubuntu using PAssenger and nginx.

Everything is running fine except rails/nginx. When I try to start it, I get this message:

* Starting Nginx Server...
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()
   ...done.

Not sure what the problem is. Do I have to use nginx instead of apache? I'm just a novice at this point, so I'd appreciate it if any answers kept that in mind.

Edit

apache2ctl -S outputs this:

 default server pixelcraftwebdesign.com (/etc/apache2/httpd.conf:4)
 port 80 namevhost pixelcraftwebdesign.com (/etc/apache2/httpd.conf:4)
 port 80 namevhost opsandss.com (/etc/apache2/httpd.conf:8)
 port 80 namevhost ergo-metric.com (/etc/apache2/httpd.conf:16)
 port 80 namevhost admin.nflspot.com (/etc/apache2/httpd.conf:24)
 port 80 namevhost utcmeme.com (/etc/apache2/httpd.conf:29)
 port 80 namevhost ruby.pixelcraftwebdesign.com (/etc/apache2/httpd.conf:37)
wildcard NameVirtualHosts and _default_ servers:
*:*                    is a NameVirtualHost
         default server myServer (/etc/apache2/sites-enabled/000-default:1)
         port * namevhost myServer (/etc/apache2/sites-enabled/000-default:1)
         port 443 namevhost myServer (/etc/apache2/sites-enabled/default-ssl:2)
Kevin Brown
  • 263
  • 2
  • 12
  • 1
    Which service do you want to be used when someone connects to your server on the default port for HTTP? It can't be both at the same time - only one can bind to port 80 (hence the error). – Shane Madden Mar 20 '12 at 00:19
  • well, I guess apache. apache needs to point to website1.com and website2.com, but I want ruby.website1.com or website3.com to point to nginx--I JUST WANT RoR TO WORK! – Kevin Brown Mar 20 '12 at 00:24
  • I changed the listen port to 8000 and removed this error....but when I go to ruby.website1.com, I can't get my page... – Kevin Brown Mar 20 '12 at 00:27
  • Do I have to use symlinks, or is the root directive sufficient? – Kevin Brown Mar 20 '12 at 04:22
  • Huh? How are sum links involved? Please see my comment on the answer below. – Shane Madden Mar 20 '12 at 05:44
  • See last step in this tutorial: http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html – Kevin Brown Mar 20 '12 at 15:10
  • That's for enabling the config that you put in that file in nginx - but we're working with the Apache configuration, correct? – Shane Madden Mar 20 '12 at 15:19
  • Both? My apache sites are working, and correctly forwards my ruby.website1.com to port 8000--which nginx should pick up? – Kevin Brown Mar 20 '12 at 15:20
  • Have you confirmed that it is forwarding the requests in Apache's logs? Safari wouldn't display that error if Apache were working correctly and nginx were not. – Shane Madden Mar 20 '12 at 15:22
  • Alright. Where are apache logs located? :/ I'm embarrassed to ask... – Kevin Brown Mar 20 '12 at 15:33
  • On Ubuntu, I believe it's `/var/log/apache2` – Shane Madden Mar 20 '12 at 15:38
  • access log is empty...error log doesn't look important... – Kevin Brown Mar 20 '12 at 17:02
  • Have you restarted Apache since making the changes? What output do you get from `apache2ctl -S`? – Shane Madden Mar 20 '12 at 18:39
  • See edit...I corrected an error. – Kevin Brown Mar 20 '12 at 20:18
  • Seems that you have extra config in the `sites-enabled` directory that you're not using - can you disable those? Has Apache been restarted? And are you on the same local area network as the server? – Shane Madden Mar 20 '12 at 21:08
  • Ran `a2dissite` for those and reloaded with no errors--same problem from the browser after restarting apache...not on same network. – Kevin Brown Mar 21 '12 at 01:22
  • Can you do some debugging on the client connection? Is the wildcard DNS resolving to the correct server? Can you use either a web browser that gives you a more useful error message (Chrome) or do a packet capture on the HTTP connection? – Shane Madden Mar 21 '12 at 01:26

2 Answers2

1

You have Apache occupying port 80. If you don't move/rename Nginx 'site-enabled/default' config file (introduced recently in 1.0+) Nginx will attempt ot start on port 80 no matter what - even you specify a different listen port for Nginx.

Move/rename the file, and indicate a different port with 'listen' directive in your 'nginx.conf'.

GWAN
  • 11
  • 1
1

Configure Apache to forward requests for the Ruby domains to nginx, which you now have listening on port 8000.

Make sure you've got a NameVirtualHost *:80 somewhere (you probably do have it in /etc/apache2/ports.conf, since you have two sites on Apache). And enable mod_proxy (a2enmod proxy). Then add this config as a new vhost:

<VirtualHost *:80>
    ServerName ruby.website1.com
    ServerAlias website3.com
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8000/
    ProxyPassReverse / http://127.0.0.1:8000/
</VirtualHost>
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • Awesome start! Now, I have this pointing to the name ruby.website1.com...which fails to open a page--so the problem now is with nginx's config? or perhaps my ruby installation? – Kevin Brown Mar 20 '12 at 00:49
  • In what way does it fail - do you get an HTTP error code? – Shane Madden Mar 20 '12 at 00:51
  • Just says "Safari can't open this page." My server is setup in a way that any subdomain points to my main website. – Kevin Brown Mar 20 '12 at 00:55
  • Check Apache's logs to see if it's getting hit when you try to access it. Are you behind the same NAT/firewall as the server? – Shane Madden Mar 20 '12 at 00:57