Apache在同一IP上的多个虚拟主机(不同的URL) [英] Apache multiple virtual hosts on the same same ip(diffrent url's)

查看:363
本文介绍了Apache在同一IP上的多个虚拟主机(不同的URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu机器内的apache服务器上有2个虚拟主机(bugzilla和主板审查).

I have 2 virtual hosts(bugzilla and board review) on an apache server sitting inside an ubuntu machine.

我有一个可以使用的外部ip地址(启用了一个端口),所以我不能为虚拟主机分配不同的主机名或不同的端口.(如果我输入错了,请更正)

I have one external ip address I can use(with one port enabled) so I can't assign different host names or different ports for the virtual hosts.(correct me if I'm wrong)

我希望用户能够编写以下内容: http://ip-address:port/bugzilla 并请求转到bugzilla 并 http://ip-address:port/review 的请求进入审核委员会.

I want the user to be able to write the following: http://ip-address:port/bugzilla and for the requests to go to bugzilla and for requests from http://ip-address:port/review to go to the review board.

我尝试了从第一个虚拟主机到第二个虚拟主机的反向代理,但这没用.

I tried reverse proxying from the first vhost to the second but that didn't work.

bugzilla conf文件使用cgi,审查委员会使用wsgi.

The bugzilla conf file uses cgi and the review board uses wsgi.

有没有简单的方法可以完成上述任务?

Is there a simple way of accomplishing the above?

谢谢.

推荐答案

您可以使用别名指令.

Alias指令允许将文档存储在本地文件系统中,而不是在DocumentRoot下.带有(%解码)的URL 以URL-path开头的路径将被映射到以本地开头的文件 与目录路径. URL路径区分大小写,即使在 不区分大小写的文件系统.

The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path. The URL-path is case-sensitive, even on case-insensitive file systems.

别名"/image""/ftp/pub/image"请求 http://example.com/image/foo.gif 会导致服务器返回 文件/ftp/pub/image/foo.gif.仅匹配完整的路径段, 因此上述别名与的请求不匹配 http://example.com/imagefoo.gif .对于更复杂的匹配,请使用 正则表达式,请参见AliasMatch指令.

Alias "/image" "/ftp/pub/image" A request for http://example.com/image/foo.gif would cause the server to return the file /ftp/pub/image/foo.gif. Only complete path segments are matched, so the above alias would not match a request for http://example.com/imagefoo.gif. For more complex matching using regular expressions, see the AliasMatch directive.

您的虚拟主机文件如下所示

Your Virtual host file would look like this

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName ip-address:port/bugzilla 
    Alias "/bugz" "var/www/html/bugz"
    Alias "/wow" "var/www/html/wow"    
    DocumentRoot /path/to/yourwebsite  
</VirtualHost>

实现在同一IP上拥有多个虚拟主机的目标.

Achieving your goal of having multiple virtual hosts on the same IP.

它的GIF有效

注意

  • 这适用于Apache 2.4.18
  • GIF显示具有两个不同虚拟主机条目的VirtualHost配置.对这个答案的评论之一说,不同的虚拟主机不起作用.但是只要服务器名称不同,它们就可以.
  • This is working for Apache 2.4.18
  • The GIF shows a VirtualHost configuration with two different virtual host entries. One of the comments to this answer said different virtual hosts don't work. But they do, as long as the server name is different.

这篇关于Apache在同一IP上的多个虚拟主机(不同的URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆