多个Rails应用程序在同一个子域?

我最近决定尝试Rails。 在使用PHP时,我只将所有的PHP项目放在同一个目录中。 例如,我可能有http://ubuntu/app1http://ubuntu/app2

我为Rails创build了一个子域( http://ruby.ubuntu ),安装了Rails和Passenger,一切正常。 但是,我可能是错的,但它看起来像我只能有一个Rails应用程序每个子域?

我的VirtualHost如下:

 <VirtualHost *:80> ServerName ruby.ubuntu ServerAdmin webmaster@localhost DocumentRoot /var/www/ruby/blog/public <Directory /var/www/ruby/blog/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all RailsEnv development </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 

我所有的PHP和杂项。 文件存储在/var/www/main 。 我想能够将所有的Rails应用程序存储在/var/www/ruby 。 我尝试将DocumentRoot更改为/var/www/ruby ,但是我不认为这很简单。 当我浏览到一个Rails应用程序的Welcome Welcome页面并点击“关于我的应用程序的环境”时,我得到一个404页面,但是当DocumentRoot设置为public目录时,我得到了预期的结果。

我不想每次创build新项目时都必须创build一个新的子域。 有什么办法可以做到这一点,所以我可以将所有的应用程序存储在/var/www/ruby ,浏览到http://ruby.ubuntu将让我访问我所有的Rails应用程序? 这样,如果我想创build一个新的应用程序,我所要做的就是rails new app ,不需要Apache .htaccess或VirtualHostconfiguration。

您可以根据需要为许多导轨应用程序提供服务。

如果使用apache httpd和乘客,这里是步骤:

只需将每个rails应用程序的公共文件夹链接到apache的DocumentRoot作为子文件夹即可。 然后在你的apacheconfiguration中添加一个RailsBaseURI指令,告诉乘客给定的文件夹是一个rails应用程序。

假设你有两个rails应用程序rapp1和rapp2。 比方说你的apache DocumentRoot是/ var / www / html

  ln -s rapp1 /var/www/html/rapp1 ln -s rapp2 /var/www/html/rapp2 

现在打开你的Apache虚拟主机configuration文件,并添加以下两行

  RailsBaseURI /rapp1 RailsBaseURI /rapp2 

重新启动你的apache服务器,当你访问http://servername/rapp1 ,你的rails应用程序会被服务

我可能会错,但我相信你想要实现的是所谓的Sub-URI的。

使用ruby.ubuntu子域,然后每个应用程序运行在不同的/子目录下。

进一步阅读: http : //collab.stat.ucla.edu/users/jose/weblog/9e335/

它看起来像你试图使用SubURIs。 乘客可以支持他们,但你需要调整你的虚拟主机configuration一点点。

Apache的Passenger Docs解释了如何做,以及一个例子来帮助你。