2015-04-16 79 views
2

我刚开始学习PHP,我试图通过使用XAMPP在本地托管我自己的PHP网站。阿帕奇虚拟主机404找不到

我想创造的虚拟主机有:

网址:myphpwebsite.local

端口:8088

但是,当我试图通过浏览器访问这个网站我有一个:

未找到 HTTP错误404。未找到请求的资源。

有谁知道这个问题是什么?

我的httpd-vhosts.conf

NameVirtualHost 127.0.0.1:8088 
<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/xampp/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost myphpwebsite.local> 
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
    ServerName myphpwebsite.local 
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log" 
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined 

    <Directory "C:/Microsoft/Workspace/myphpwebsite"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

而我的C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ ETC \ hosts文件:

127.0.0.1  localhost 
127.0.0.1 myphpwebsite.local 

任何帮助,将不胜感激!

回答

0

NameVirtualHost指令需要完全匹配VirtualHost的值,并且您需要在每个实例中指定端口。如果你想使用端口8088进行myphpwebsite.local,你需要做的:

NameVirtualHost 127.0.0.1:8088 
<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/xampp/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
    ServerName myphpwebsite.local 
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log" 
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined 

    <Directory "C:/Microsoft/Workspace/myphpwebsite"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

通知之VirtualHost开始标签是相同的;这是ServerName值,它实际上告诉Apache此特定指令适用于哪个域。进行更改后重新启动服务器。看看这个页面的更多信息:http://httpd.apache.org/docs/2.2/vhosts/name-based.html

希望这有助于!

+0

@Avil如果这仍然不起作用,确保你的'DocumentRoot'的文件夹确实存在,'Listen 8088'在你的httpd.conf中。我犯了更严重的错误。 :) –

1

我不知道我是否有很多帮助,但使用WAMP,这里是我的设置。我在端口80上侦听,我使用8080作为我的tomcat服务器。

hosts文件

127.0.0.1 local.mysite.com 

的httpd-vhosts.conf

# 
# Use name-based virtual hosting. 
# 
NameVirtualHost *:80 

.... 

<Directory "c:/wamp/www"> 
    Options Indexes MultiViews FollowSymLinks 
    Order Deny,Allow 
    Deny from all 
    Allow from 127.0.0.1 
</Directory> 
<VirtualHost *:80> 
    ServerName localhost 
    DocumentRoot "c:/wamp/www" 
</VirtualHost> 

<Directory "c:/wamp/www/path/to/site/root"> 
    Options Indexes MultiViews FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory> 
<VirtualHost *:80> 
    ServerName local.mysite.com 
    DocumentRoot "c:/wamp/www/path/to/site/root" 

    ServerAdmin [email protected] 

    ProxyPreserveHost Off 
    RewriteEngine On 
    AllowEncodedSlashes NoDecode 
    #AllowEncodedSlashes On 

    ErrorLog "c:/wamp/www/path/to/logs/error.log" 
    CustomLog "c:/wamp/www/path/to/logs/access.log" common 
</VirtualHost> 

.... 

然后,我可以访问我的本地站点是这样的:http://local.mysite.com

希望这有助于...

0
  1. 确保有任何目录要打开文件/ htaccess的/指数或404可以来自于)

  2. 尝试下面用一个,最终取代你的端口:

    <VirtualHost *:80> 
        DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
        ServerName myphpwebsite.local 
        </VirtualHost> 
    
  3. 问题是你的Apache在8088端口上运行/服务? 例如我的xamp在80和443上运行...

  4. xamp控制面板非常方便,它有很好的日志按钮,将打开您的日志文件,以显示您的PHP和Apache错误等检查出来。

尝试使用默认端口,如果它的工作,这意味着如果你真的想要,你需要与端口一起玩。

只是一个快速提示,.com比.local短,如果您使用的是Chrome浏览器,并且它的工作方式与我的一样,那么大多数情况下,something.local会将您重定向到Google搜索(并且我喜欢我的搜索,你可以把它关掉;))