如何获得子域与文件夹链接?

我正在运行xampp,在开发服务器的Windows上有Apache。 我需要使用本地主机的子域来访问我的本地主机/图像/文件夹转到h ## p://images.localhost

不过,我有麻烦,我已经张贴在下面的图像显示我的问题。

所以问题是如何在Apache上设置一个子域名,并且实际上它可以用于像我需要的文件夹?

请查看此图片,对不起,新用户不能发布更多的1url和NO图像,所以这里是我的1url重要的形象

http://www.freeimagehosting.net/uploads/b0194b8e68.jpg

更新后的版本

My apache conf file NameVirtualHost localhost:8080 <VirtualHost localhost:8080> ServerName localhost ServerAdmin [email protected] DocumentRoot c:\server\htdocs </VirtualHost> <VirtualHost images.localhost:8080> ServerName images.localhost ServerAdmin [email protected] DocumentRoot c:\server\htdocs\images </VirtualHost> My windows host file 127.0.0.1 images.localhost 127.0.0.1 *.localhost 

就我所了解的Apache虚拟主机而言,问题在于你在虚拟主机configuration中使用了一个全面的方法,并使用一个相互DocumentRoot,而不是明确定义每个VHost的名称和DocumentRoot:

*:8080是您的基本NameVirtualHost设置。

这将捕获所有的请求到:8080,它将把所有请求redirect到与指令匹配的虚拟主机。

当你有两个命名为相同的命令的Vhost指令时,这个指令的DocumentRoot与服务器的DocumentRoot相匹配就会产生问题。 如果服务器没有单独的“Overriding”DocumentRoot,则Apache将评估每个Vhost的DocumentRoot,如果多个Vhost共享根path,则find它遇到的值的“Occam's Razor”。

在这种情况下… \ htdocs是两者的DocumentRoot,因为… \ images包含 … \ htdocs中。 因此,任何请求都会自动默认为提供… \ htdocs作为其DocumentRoot的Vhost。

我意识到这有点混乱,所以要解决这个问题:切换到基于名称的虚拟主机。

更新(2009-08-25)
在我们继续之前,我需要澄清一些事情:

Apache和其他Web服务器从不听:8080默认情况下。 另外,像Firefox这样的networking客户端从来没有向8080提出请求。 我认为你从你原来的post可以理解,因为你的VHost指令显示了非标准端口:8080。 现在,我不太清楚。

为了使我的文章的前一版本在设置时能够为您工作(没有端口80redirect或您有什么),您需要在请求页面时指定端口:

http:// localhost:8080和http://images.localhost:8080

我应该包括这些信息。 正如我所说,我认为这是从你原来的职位清楚。 我为此道歉。 通过扩展,我还假定你是这样设置的,因为另一台服务器正在监听端口80.如果是这样的话,那么你可以考虑把两台服务器组合成一个设置,或者在你使用xampp 。

因此,让我们纠正VHost指令来侦听端口80,这是服务器和客户端分别从服务器和服务器请求的默认端口。

我也将得到关于定义您服务数据的文件夹的本地化权限的肛门保留,因为我担心有一个/ Directive正在消耗您从网站获取页面的能力。

更新的 VirtualHost指令(2009-08-25):

 NameVirtualHost localhost:80 <VirtualHost localhost:80> ServerName localhost # Naturally, this can be changed to a real email. ServerAdmin [email protected] # Set our DocRoot for the VHost. DocumentRoot c:\xampp\htdocs # Define access perms for our DocRoot. <Directory "c:\xampp\htdocs"> # We're going to define Options, Override perms, and Allow directives. # FollowSymLinks probably doesn't work in Windows, but we'll keep it for posterity. Options Indexes MultiViews FollowSymLinks # Disallow Override AllowOverride None # Setup 1. Allow only *from* localhost. Comment out the following 3 lines, # and uncomment Setup 2 below to allow access from all. Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 # Setup 2. Allow all. Uncomment the following 2 lines, and comment out Setup 1. #Order allow,deny #Allow from all </Directory> </VirtualHost> <VirtualHost images.localhost:80> ServerName images.localhost # Naturally, this can be changed to a real email. ServerAdmin [email protected] # Set our DocRoot for the VHost. DocumentRoot c:\xampp\htdocs\images # Define access perms for our DocRoot. <Directory "c:\xampp\htdocs\images"> # We're going to define Options, Override perms, and Allow directives. # FollowSymLinks probably doesn't work in Windows, but we'll keep it for posterity. Options Indexes MultiViews FollowSymLinks # Disallow Override AllowOverride None # Setup 1. Allow access only from localhost. Comment out the following 3 lines, # and uncomment Setup 2 below. Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 # Setup 2. Allow all. Uncomment the following 2 lines, and comment out Setup 1. #Order allow,deny #Allow from all </Directory> </VirtualHost> 

如果没有相应的虚拟主机的DNS名称,Apache会对此设置感到愤怒,所以之前关于修改系统主机文件的build议仍然是准确的。 请注意,当您编辑主机文件时,您可以将单个IP的所有别名放在同一行,这样可以避免一些混淆。

 127.0.0.1 localhost images.localhost 

你也可以做基于IP的虚拟,但我不会推荐它。 这比你正在做的事情要复杂得多,当你使用SSL处理多个虚拟主机时,这只是“真正”必要的。

无论如何,我所描述的设置完全按照我的系统(Ubuntu 8.10 x86_64,Apache 2.2.9)的预期工作,并且也应该在你的系统上正常工作。

我会想象你的问题是试图做一个“本地主机”的子域。 最好的办法是将您的服务器名称更改为“localdomain.com”和“images.localdomain.com”(任何事情都会实现),然后修改您的主机文件以将该域映射到127.0.0.1

已经有一段时间,因为我已经使用Windows(对不起),但我相信主机文件是在C:\ WINDOWS \ SYSTEM32 \ etc \主机

而假域的格式将是这样的:

 localdomain.com 127.0.0.1 

那么,你只需要反弹你的XAMPP服务器,一切都应该是好的。

希望帮助:)

configuration对我来说很好看。 检查简单的问题,如更改configuration文件后重新启动Apache等

如RFC 2606 .localhost中所述。 被视为特殊。

但还有一件事要看:你的默认目录是什么? 这可能是你的虚拟设置没有正常工作。 但是相反,服务器本身的DocumentRoot总是处理请求。

问题是“本地主机”总是parsing为127.0.0.1,但localhost的子域名(如“images.localhost”)未定义,因此无法parsing。 您可以通过编辑您的系统的主机文件(通常在c:\ windows \ system32 \ drivers \ etc中)并添加以下行来更正本地文件:

 127.0.0.1 images.localhost 

您还可以添加:

 127.0.0.1 *.localhost 

保存主机文件后,您的子域应正确parsing。

编辑:我看到你有虚拟主机configuration监听端口8080,但你的URL不包括端口号。 你需要浏览到8080这样的地址:

 http://images.localhost:8080/layout/homepage/welcome_image.jpg 

或者,您可以更改虚拟主机来侦听:80。

我猜只是本地主机工作的原因是你的主要Apache conf有一个Listen 127.0.0.1DocumentRoot c:\xampp\htdocs

我甚至尝试在我的主机文件中使用一个真正的域名,我的电脑将超时试图加载它

也许你的名字parsing有问题。 您可以从命令行(开始 – >运行 – >“cmd”)尝试“ping images.localhost”

如果这个子域名不工作,也许你可以尝试一个真正的。 我的最后一篇文章可能会有所帮助: 42foo:您所需的所有虚拟主机用于Web开发

我有这个工作在一些领域,虽然我把它们全部链接到同一个文档根目录:

 <VirtualHost *:80> DocumentRoot /srv/apps/mydomain/current/public ServerName mydomain.com ServerAlias www.mydomain.com </VirtualHost> <VirtualHost *:80> DocumentRoot /srv/apps/mydomain/current/public ServerName assets0.mydomain.com ServerAlias assets1.mydomain.com ServerAlias assets2.mydomain.com ServerAlias assets3.mydomain.com </VirtualHost>