[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 911
  • Last Modified:

VHost Configuration Problem

I'm having a problem configuring a vhost. It's for a Ruby on Rails application, the problem is the vhost is being accessed from every subdomain, not just the one i would like it assigned to. Here is my configuration.

<VirtualHost *:80>

  ServerName appname.server.com
  DocumentRoot /var/www/rails/appname

  <Directory "/var/www/rails/appname/public">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>

  <Proxy balancer://mongrel_cluster>
    BalancerMember http://127.0.0.1:8805
  </Proxy>

  RewriteEngine On

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
  RewriteRule ^(.+[^/])$ $1/ [R]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} \.php
  RewriteRule ^(.*)$ $1 [QSA,L]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
  RewriteRule ^(.*)$ $1/index.html [QSA,L]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.php -f
  RewriteRule ^(.*)$ $1/index.php [QSA,L]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
  RewriteRule ^(.*)[^/]$ $1/ [QSA,L]

  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml

  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4.0[678] no-gzip
  BrowserMatch bMSIE !no-gzip !gzip-only-text/html

  php_value include_path /var/www/rails/appname/php:/usr/local/lib/php:.
# php_value auto_prepend_file /var/www/rails/appname/php/auto_prepend.php

  # this not only blocks access to .svn directories, but makes it appear
  # as though they aren't even there, not just that they are forbidden
  <DirectoryMatch "^/.*/\.svn/">
    ErrorDocument 403 /404.html
    Order allow,deny
    Deny from all
    Satisfy All
  </DirectoryMatch>

</VirtualHost>
0
gf3
Asked:
gf3
  • 3
  • 2
1 Solution
 
gf3Author Commented:
OK I got that junk working! But I have a different problem now. I have configured another VHost, works great. The only problem is everything is served from that VHost and not the document root. Here is my VHost configuration:

<VirtualHost *:80>
        ServerName devo.server.com
        DocumentRoot /var/www-devo
        ServerAdmin gianni@server.com
        ErrorLog /var/log/httpd/devo.server.com-error_log
        CustomLog /var/log/httpd/devo.server.com-access_log common
        RewriteEngine On

        <Directory /var/www-devo>
                Options ExecCGI FollowSymLinks
                AllowOverride all
                Allow from all
                Order allow,deny
        </Directory>
</VirtualHost>
0
 
samriCommented:
hi gf3,

If I got the situation right, now you had (as mentioned) 2 Vhosts configured

Vhost#1
ServerName appname.server.com
  DocumentRoot /var/www/rails/appname

Vhost#2
ServerName devo.server.com
        DocumentRoot /var/www-devo

How does the Vhost appears in the apache config.  I mean the order.   devo then appname, or appname then devo.  Reason for asking this is -- apache would

http://httpd.apache.org/docs/2.2/vhosts/name-based.html
>> f no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

you could do a
 httpd -t -D DUMP_VHOSTS

to list the vhosts and how the are ordered.

Once you had identified that, reorder, or set the appropriate ServerName of ServerAlias directive in the respective Vhost container according to the names it is suppose to appear in the URL.  Since you had the rewrite directive in one of the vhost (appname), do ensure that the resulting rewritten URL -- and ensure that it conform to the desired Vhost.  Remember that anything that does not match any configured vhost would be served by the first configured Vhost.

HTH.
0
 
gf3Author Commented:
Sorry I should have cancelled this question, the guys at irc.freenode.net#apache helped me figure it out. When adding a vhost you need to configure one for your primary domain as well. Otherwise the first one will be used as the default.
0
 
samriCommented:
I am glad you had found a solution

You may request for PAQ/Refund in Community Support - http://www.experts-exchange.com/Community_Support/General/

or if you feel like awarding the pts, you could accept my answer since its very much telling the same thing.  

cheers.

0
 
gf3Author Commented:
yea no probs :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now