【问题标题】:Apache virtual host 404 not found未找到 Apache 虚拟主机 404
【发布时间】:2015-06-22 22:43:33
【问题描述】:

我刚开始学习 php,我正在尝试使用 XAMPP 在本地托管我自己的 php 网站。

我想创建虚拟主机:

网址: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

任何帮助将不胜感激!

【问题讨论】:

    标签: php apache xampp virtualhost


    【解决方案1】:

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

    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

    希望这会有所帮助!

    【讨论】:

    • @Axvil 如果这仍然不起作用,请确保您的DocumentRoot 的文件夹确实存在并且Listen 8088 在您的httpd.conf 中。我犯了更愚蠢的错误。 :)
    【解决方案2】:

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

    主机文件

    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 me@email.com
    
        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

    希望这会有所帮助...

    【讨论】:

      【解决方案3】:
      1. 确保有 file/htaccess/index 或您要打开的目录中的任何内容,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 并且它像我的一样工作,那么大部分时间 some.local 会将您重定向到谷歌搜索(我喜欢我在那里的搜索,你可以关掉它;))

      【讨论】:

        【解决方案4】:

        确保您正在使用的端口没有被其他服务使用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-26
          • 2021-10-12
          • 1970-01-01
          • 2011-06-19
          • 2014-08-06
          • 2019-08-25
          • 2012-04-26
          • 2012-09-25
          相关资源
          最近更新 更多