Apache alias virtual host
Asked Answered
H

2

11

I have two applications running in the same server and I would like to have one served from subpath in the url (i.e):

  • foo.com -> /var/www/foo
  • foo.com/bar -> /var/www/bar

I'm trying to do an alias but is not working:

<VirtualHost *:80>
  ServerAdmin [email protected]
  ServerName foo.com
  DocumentRoot /webapps/foo/current/public
  <Directory /webapps/foo/current/public>
    AllowOverride all
    Options -MultiViews
  </Directory>
  RailsEnv staging
  Alias /blog /webapps/blog/current
 <Directory /webapps/blog/current>
   allow from all
   Options +Indexes
 </Directory>

Do you know why this is not working?

I also tried serverpath directive without any success.

Do you know how to achieve this?

Thanks in advance.

Holder answered 26/8, 2011 at 17:47 Comment(9)
Is your virtualhost working at all? Cos if you need to access it via www. as well as the root of the domain, I would say you need a ServerAlias www.foo.com in there...Faris
Also, does either app use any mod_rewriteing?Faris
Oh sorry, actually the address is without the www. I fixed that on the post. The virtualhost is working, I'm able to access it, but if I go to /blogs/ it does nothing. Both applications have mon_rewrite inside their .httaccessHolder
What do you get? A 404? And what is in the Apache logs? And are you using a [PT] on you rewrite rules for the /blogs directory?Faris
I get a 404 that is handled by /var/www/foo. I don't have a [PT] rewrite rule. Actually I don't have a rewrite for the /blog... I'm using for other things. Should I have a rewrite and the alias in order to make it work?Holder
Not necessarily, it depends on your app - it's just that some rewrite rules wont work with aliases unless you have a [PT] (although not all rules, it depends on what it does). Let me have a play with the Apache install on my laptop and I'll get back to you...Faris
what about using a subdomain such as bar.foo.com. This way it will have its own vhost configuration.Mahau
the subdomain is the way I have it know, but we wanted to change it to the other way.Holder
Besides tuning apache configuration, have you ever tried create a symbolic link /var/www/bar to /var/www/foo/barUnlucky
U
3

Use AliasMatch instead of Alias:

AliasMatch ^/bar/?(.*) /var/www/bar/$1

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1
Undertone answered 1/11, 2013 at 22:22 Comment(0)
F
1

Have you considered using another separate subdomain, like bar.foo.com for your other application?

Here's how you'd set that up:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/foo
    ServerName foo.com
    ServerAlias foo.com www.foo.com
    ErrorLog logs/foo.com_Error_Log
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/bar
    ServerName bar.foo.com
    ErrorLog logs/bar.foo.com_Error_Log
</VirtualHost>
Foretell answered 10/9, 2014 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.