2010-09-08 32 views
1

我有一臺在Apache上運行3個站點的Linux服務器。我們稱之爲RailsApp1,RailsApp2和SimpleApp。兩個Rails應用程序都使用Mongrel羣集。另一個應用程序只是一個HTML文件。我在Apache中爲每個站點設置了不同的虛擬主機文件,以及兩個Rails站點的mongrel_cluster.yml文件(所有代碼均位於底部)。在Apache和Mongrel上爲Rails應用程序設置虛擬主機

隨着一切設置,我可以啓用在Apache的網站就好了。我可以爲每個Rails站點啓動Mongrel羣集。事實上,在我的瀏覽器中訪問www.simpleapp.com和www.railsapp1.com工作得很好。 但是,www.railsapp2.com給了我很多麻煩。服務器不用顯示railsapp2的代碼,而是返回railsapp1的HTML。如果我在Apache中禁用railsapp1,然後轉到www.railsapp2.com,服務器現在返回simpleapp的HTML。只有當我在Apache中禁用railsapp1和railsapp2時,服務器纔會正確響應www.railsapp2.com上的請求。

有關爲什麼會發生這種情況的任何想法?

SimpleApp的VHOST文件:

<VirtualHost *:80> 
    ServerName www.simpleapp.com 
    ServerAlias simpleapp.com 
    DocumentRoot /home/nudecanaltroll/public_html/simpleapp 
</VirtualHost> 

RailsApp1的VHOST文件:

<VirtualHost *:80> 
    ServerName railsapp1.com 
    DocumentRoot /home/nudecanaltroll/public_html/railsapp1/public 
    RewriteEngine On 
    <Proxy balancer://mongrel1> 
    BalancerMember http://127.0.0.1:5000 
    BalancerMember http://127.0.0.1:5001 
    BalancerMember http://127.0.0.1:5002 
    </Proxy> 
    # Timeout in 30 seconds 
    ProxyTimeout 30 
    # Make sure people go to www.railsapp1.com, not railsapp1.com 
    RewriteCond %{HTTP_HOST} ^railsapp1\.com$ [NC] 
    RewriteRule ^(.*)$ http://www.railsapp1.com$1 [R=301,NE,L] 
    # Redirect all non-static requests to thin 
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
    RewriteRule ^/mongrel1(.*)$ balancer://mongrel1%{REQUEST_URI} [P,QSA,L] 
    # Proxy Stuff 
    ProxyPass/balancer://mongrel1/ 
    ProxyPassReverse/balancer://mongrel1/ 
    ProxyPreserveHost on 
    <Proxy *> 
    Order deny,allow 
    Allow from all 
    </Proxy> 
    # Custom log file locations 
    ErrorLog /home/nudecanaltroll/public_html/railsapp1/log/error.log 
    CustomLog /home/nudecanaltroll/public_html/railsapp1/log/access.log combined 
</VirtualHost> 

RailsApp2的VHOST文件:

<VirtualHost *:80> 
    ServerName railsapp2.com 
    DocumentRoot /home/nudecanaltroll/public_html/railsapp2/public 
    RewriteEngine On 
    <Proxy balancer://mongrel2> 
    BalancerMember http://127.0.0.1:6000 
    BalancerMember http://127.0.0.1:6001 
    BalancerMember http://127.0.0.1:6002 
    </Proxy> 
    # Timeout in 30 seconds 
    ProxyTimeout 30 
    # Make sure people go to www.railsapp2.com, not railsapp2.com 
    RewriteCond %{HTTP_HOST} ^railsapp2\.com$ [NC] 
    RewriteRule ^(.*)$ http://www.railsapp2.com$1 [R=301,NE,L] 
    # Redirect all non-static requests to thin 
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
    RewriteRule ^/mongrel2(.*)$ balancer://mongrel2%{REQUEST_URI} [P,QSA,L] 
    # Proxy Stuff 
    ProxyPass/balancer://mongrel2/ 
    ProxyPassReverse/balancer://mongrel2/ 
    ProxyPreserveHost on 
    <Proxy *> 
    Order deny,allow 
    Allow from all 
    </Proxy> 
    # Custom log file locations 
    ErrorLog /home/nudecanaltroll/public_html/railsapp2/log/error.log 
    CustomLog /home/nudecanaltroll/public_html/railsapp2/log/access.log combined 
</VirtualHost> 

RailsApp1的mongrel_cluster.yml文件:

--- 
address: 127.0.0.1 
log_file: log/mongrel.log 
port: 5000 
cwd: /home/nudecanaltroll/public_html/railsapp1 
environment: production 
pid_file: /home/nudecanaltroll/public_html/railsapp1/tmp/pids/mongrel.pid 
servers: 3 

RailsApp2的mongrel_cluster.yml文件:

--- 
address: 127.0.0.1 
log_file: log/mongrel.log 
port: 6000 
cwd: /home/nudecanaltroll/public_html/railsapp2 
environment: production 
pid_file: /home/nudecanaltroll/public_html/railsapp2/tmp/pids/mongrel.pid 
servers: 3 

回答

0

我想通了。由於我不知道的原因,我需要爲RailsApp2設置ServerAlias,並添加「www」。在ServerName前面。所以railsapp2.com虛擬主機文件的頂部,現在看起來是這樣的:

<VirtualHost *:80> 
    ServerName www.railsapp2.com 
    ServerAlias railsapp2.com 
    ... 

出於某種原因,RailsApp1不需要這些變化才能正常工作。