Martyn
Martyn

Reputation: 6383

How do I create a virtual host in Apache for a rails app

I've currently got Ubuntu server running on another computer on my home network. I've installed LAMP for my PHP apps, and ruby for my ruby on rails apps. In my /etc/hosts file I put in a domain name (not real yet) of the app I wish to attach the domain name to. So, for now I guess I'm just simulating typing in that domain and accessing my app on my server when it's finished and I have a real http request coming in for that address. Here is my /etc/hosts file:

27.0.0.1       localhost
127.0.1.1       mB590

# I want this to point to my rails app
192.168.24.100  example.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I've, on my server, created a virtual host file called example.com:

<VirtualHost *>
    RailsEnv development
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example/public
</VirtualHost>

On another computer on the same network I can type in example.com and my apache Welcome page appears. If I type example.com:3000 it points to my rails app as I have setup a virtual host for that to happen. But I want to set it up so that when I type example.com it points to my rails app, without having to specify the port number. I tried the following, then restarted apache and rails server:

<VirtualHost *:3000>
    RailsEnv development
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example/public
</VirtualHost>

.. didn't do anything. I then tried putting in Listen 3000:

Listen 3000
<VirtualHost *>
    RailsEnv development
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /var/www/example/public
</VirtualHost>

.. but got this error:

=> Booting WEBrick
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-05-21 20:17:13] INFO  WEBrick 1.3.1
[2014-05-21 20:17:13] INFO  ruby 2.0.0 (2014-02-24) [i686-linux]
[2014-05-21 20:17:13] WARN  TCPServer Error: Address already in use - bind(2)
Exiting
/home/martyn/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
.
.
.

What do I need to do to set this up how I want it? (type in the URL, without the port number and it will be directed to my app)

Upvotes: 0

Views: 1901

Answers (1)

rajesh023
rajesh023

Reputation: 714

The issue is that you are already listening to port 3000, from the config I see Listen 3000 which is bound to port 3000 already, when you run the server as you did by default it takes port 3000. Hence the error.

Comment the Line Listen 3000, and try it should work.

Upvotes: 1

Related Questions