简体   繁体   中英

Apache alias virtual host

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

  • 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 webmaster@foo.com
  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.

Use AliasMatch instead of Alias :

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

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$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 webmaster@foo.com
    DocumentRoot /var/www/foo
    ServerName foo.com
    ServerAlias foo.com www.foo.com
    ErrorLog logs/foo.com_Error_Log
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@foo.com
    DocumentRoot /var/www/bar
    ServerName bar.foo.com
    ErrorLog logs/bar.foo.com_Error_Log
</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM