当设置新的别名时,我得到访问禁止(错误403)

我正在运行Windows 7,最近安装了XAMPP来构build一个开发环境。 我不擅长服务器端的东西,所以我有一些问题为一个项目设置别名。

到目前为止XAMPP正在运行,如果我去本地主机,我得到的XAMPP欢迎页面。 我在我的apache安装的“conf”文件夹中创build了一个“别名”文件夹。 在那里我添加了以下内容dev.conf:

<Directory "C:\Users\my_user\My%20Documents\Aptana%20Studio%203%20Workspace\project"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from 127.0.0.1 </Directory> Alias /dev "C:\Users\my_user\My%20Documents\Aptana%20Studio%203%20Workspace\project" 

但是当我去“localhost / dev”时,我得到:

访问被禁止!

您无权访问请求的对象。 它是读取保护的或不可读的服务器。

如果您认为这是服务器错误,请与网站站长联系。

错误403

我尝试了谷歌search,我发现其他类似的问题,但我似乎无法弄清楚。 有人说,你必须告诉它有权限,但在我指定允许从127.0.0.1它的conf文件。 也许这是因为我的path中有空格(虽然有些Google使用了%20的工作)。 我已经设法创build一个到不同的文件夹,并复制粘贴工作的一个,改变别名和path,它打破了,所以这告诉我,这可能与两者之一有关。

我看着我的日志文件夹,发现以下行:

[Tue Dec 13 14:59:20 2011] [error] [client :: 1] client denied by server configuration:C:/ Users / my_user / My%20Documents

我不确定是否因为错误消息只能有一定的长度而被切断,但是这绝对不是我在dev.conf文件中添加的path,我希望这可以让这个更清晰一些,因为我得到相当沮丧,我不知道该怎么尝试了。

我刚刚在Windows安装Xampp上发现了Aliases的相同问题。

解决403错误:

 <Directory "C:/Your/Directory/With/No/Trailing/Slash"> Require all granted </Directory> Alias /dev "C:/Your/Directory/With/No/Trailing/Slash" 

Xampp的默认设置应该没问题。 有些人遇到了拒绝放在根目录上的问题,所以把目录标签翻出来:

 <Directory "C:/Your/Directory/With/No/Trailing/Slash"> Allow from all Require all granted </Directory> 

会有所帮助,但目前版本的Xampp(v1.8.1在撰写本文时)并不需要它。

至于端口80的操作问题,Xampp包含一个方便的Netstatbutton来发现你的端口是什么。 解决冲突,我想这可能是IIS,但不能确定。

我使用XAMPP与Apache2.4,我有这个相同的问题。 我想离开默认的xampp / htdocs文件夹,能够从locahost访问它,并有一个虚拟主机指向我的开发区…

我的C:\xampp\apache\conf\extra\http-vhosts.conf文件的全部内容如下…

 # Virtual Hosts # # Required modules: mod_log_config # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # ##NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ##ServerName or ##ServerAlias in any <VirtualHost> block. # ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host.example.com" ##ServerName dummy-host.example.com ##ServerAlias www.dummy-host.example.com ##ErrorLog "logs/dummy-host.example.com-error.log" ##CustomLog "logs/dummy-host.example.com-access.log" common ##</VirtualHost> ##<VirtualHost *:80> ##ServerAdmin webmaster@dummy-host2.example.com ##DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com" ##ServerName dummy-host2.example.com ##ErrorLog "logs/dummy-host2.example.com-error.log" ##CustomLog "logs/dummy-host2.example.com-access.log" common ##</VirtualHost> <VirtualHost *:80> DocumentRoot "C:\xampp\htdocs" ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:\nick\static" ServerName dev.middleweek.co.uk <Directory "C:\nick\static"> Allow from all Require all granted </Directory> </VirtualHost> 

然后我更新我的C:\windows\System32\drivers\etc\hosts文件像这样…

 # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 dev.middleweek.co.uk 127.0.0.1 localhost 

重新启动你的机器,打开XAMPP控制面板并启动Apache。

现在在您的浏览器中打开您的自定义域,在上面的例子中,它将是http://dev.middleweek.co.uk

希望帮助别人!

如果你想能够查看你的新虚拟主机下的目录列表,然后在C:\xampp\apache\conf\extra\http-vhosts.conf编辑你的VirtualHost块来包含“Options Indexes”像这样…

 <VirtualHost *:80> DocumentRoot "C:\nick\static" ServerName dev.middleweek.co.uk <Directory "C:\nick\static"> Allow from all Require all granted Options Indexes </Directory> </VirtualHost> 

干杯,尼克

这个问题已经很老了,尽pipe你已经设法使它成功了,但是如果我清楚地说明你在这里提出的一些观点,我觉得这会有所帮助。

首先关于具有空格的目录名称。 我一直在玩apache2configuration文件,我发现,如果目录名称有空格,然后用双引号括起来,所有的问题消失。 例如…

  NameVirtualHost local.webapp.org <VirtualHost local.webapp.org:80> ServerAdmin a.mhawila@gmail.com DocumentRoot "E:/Project/my php webapp" ServerName local.webapp.org </VirtualHost> 

请注意DocumentRoot行的写法。

其次是关于从XAMPP禁止访问。 我发现默认的xamppconfiguration(..path到xampp / apache / httpd.conf)有一个如下所示的部分。

  <Directory> AllowOverride none Require all denied </Directory> 

改变它,并使其看起来像下面。 保存文件从xampp重新启动Apache,并解决了这个问题。

  <Directory> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride none Require all granted </Directory> 

尝试这个

sudo chmod -R 0777 / opt / lampp / htdocs / testproject

我终于搞定了。

我不确定path中的空间是否会破坏事物,但我将Aptana安装的工作空间更改为没有空间的空间。

然后,我卸载了XAMPP并重新安装了它,因为我想也许我在某处没有注意地犯了一个错字,并且认为我应该从头开始工作。

事实certificate,Windows 7有一个服务的地方,使用端口80阻止Apache启动(给它-1)的错误。 所以我改变了它监听端口8080的端口,没有更多的冲突。

最后, 我重新启动了我的电脑 ,出于某种原因XAMPP不喜欢我搞乱ini文件,只是重新启动Apache没有做的伎俩。

无论如何,这是最令人沮丧的一天,所以我真的希望我的答案结束了帮助别人!

Apache 2.4虚拟主机黑客

1.在http.conf中指定端口,在“Listen”

 Listen 80 Listen 4000 Listen 7000 Listen 9000 
  1. 在httpd-vhosts.conf中

     <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html" ServerName hitesh_web.dev ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common <Directory "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html"> Allow from all Require all granted </Directory> </VirtualHost> 

    这是第二个虚拟主机

     <VirtualHost *:80> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "E:/dabkick_git/DabKickWebsite" ServerName www.my_mobile.dev ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common <Directory "E:/dabkick_git/DabKickWebsite"> Allow from all Require all granted </Directory> </VirtualHost> 
  2. 在windows os的“.c:\ Windows \ System32 \ drivers \ etc \ host.ics”的hosts.ics文件中,

     127.0.0.1 localhost 127.0.0.1 hitesh_web.dev 127.0.0.1 www.my_mobile.dev 127.0.0.1 demo.multisite.dev 

4.现在,在浏览器中键入您的“域名”,它将ping在documentRootpath中指定的特定文件夹

5.如果你想在特定的端口访问这些文件,那么在httpd-vhosts.conf中用下面的端口号代替80,然后重新启动apache

  <VirtualHost *:4000> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html" ServerName hitesh_web.dev ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common <Directory "C:/Users/Vikas/Documents/NetBeansProjects/slider_website_hitesh/public_html"> Allow from all Require all granted </Directory> </VirtualHost> 

这是第二个虚拟主机

 <VirtualHost *:7000> ServerAdmin webmaster@dummy-host2.example.com DocumentRoot "E:/dabkick_git/DabKickWebsite" ServerName www.dabkick_mobile.dev ErrorLog "logs/dummy-host2.example.com-error.log" CustomLog "logs/dummy-host2.example.com-access.log" common <Directory "E:/dabkick_git/DabKickWebsite"> Allow from all Require all granted </Directory> </VirtualHost> 

注意:对于给定虚拟主机的端口号,你必须在浏览器中ping“ http://hitesh_web.dev:4000/ ”或“ http://www.dabkick_mobile.dev:7000/

6.完成所有这些更改后,您必须分别保存文件并重新启动apache。

如果已经通过Bitnami在Xampp(在Linux上)上安装了一个模块并更改了chown设置,请确保/opt/lampp/apps/<app>/htdocstmp usergroup是daemon ,同时将所有其他兄弟文件和文件夹您安装的用户,例如cd /opt/lampp/apps/<app>sudo chown -R root:root . ,接着是sudo chown -R root:daemon htdocs tmp