如何在Apache中为rails应用程序创建虚拟主机

时间:2014-05-21 11:24:35

标签: ruby-on-rails apache virtualhost

我目前在家庭网络上的另一台计算机上运行Ubuntu服务器。我为我的PHP应用程序安装了LAMP,并为我的ruby on rails应用程序安装了ruby。在我的/ etc / hosts文件中,我输入了一个我希望附加域名的应用程序的域名(不是真实的)。所以,现在我想我只是模拟在该域中输入并在我的服务器上访问我的应用程序,当它完成并且我有一个真正的http请求进入该地址。这是我的/ etc / hosts文件:

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

我在我的服务器上创建了一个名为example.com的虚拟主机文件:

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

在同一网络上的另一台计算机上,我可以输入example.com,然后会出现我的apache欢迎页面。如果我键入example.com:3000它指向我的rails应用程序,因为我已经设置了虚拟主机以实现这一点。但我想设置它,以便当我键入example.com时它指向我的rails应用程序,而不必指定端口号。我尝试了以下内容,然后重新启动了apache和rails server:

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

..没有做任何事情。然后我尝试输入Listen 3000

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

..但是收到了这个错误:

=> 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)
.
.
.

我需要做些什么来设置我想要的方式? (输入URL,没有端口号,它将被定向到我的应用程序)

1 个答案:

答案 0 :(得分:1)

问题是你已经在配置中看到了port 3000,我已经看到绑定到端口3000的Listen 3000了,当你运行服务器时,默认它需要端口3000因此错误。

评论专栏Listen 3000,并试一试。