Apache 别名虚拟主机

发布于 2024-12-01 12:23:39 字数 804 浏览 0 评论 0原文

我有两个应用程序在同一台服务器上运行,我希望从 url 中的子路径(即)提供一个应用程序:

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

我正在尝试创建别名但不起作用:

<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>

你知道为什么这不起作用吗?

我也尝试了 serverpath 指令,但没有成功。

你知道如何实现这一目标吗?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那小子欠揍 2024-12-08 12:23:39

使用 AliasMatch 而不是 Alias

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

或者,根据您的情况:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1

Use AliasMatch instead of Alias:

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

Or, in your case:

AliasMatch ^/blog/?(.*) /webapps/blog/current/$1
淡墨 2024-12-08 12:23:39

您是否考虑过为您的其他应用程序使用另一个单独的子域,例如 bar.foo.com

设置方法如下:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文