【问题标题】:The requested URL could not be retrieved while trying to access Laravel project on Virtual Host with XAMPP尝试使用 XAMPP 访问虚拟主机上的 Laravel 项目时无法检索请求的 URL
【发布时间】:2021-09-27 19:28:23
【问题描述】:

我想用 XAMPP 为我的 Laravel 项目创建一个虚拟主机,所以我按照以下步骤操作:

第 1 步) C:\WINDOWS\system32\drivers\etc\ 打开“hosts”文件(以管理员身份):

127.0.0.1       test.com

第 2 步) xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/freedeliveries/public"
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/freedeliveries/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>    
    ServerName www.test.com
</VirtualHost>

第 3 步) C:\xampp\apache\conf\httpd.conf。向下滚动到末尾的 Supplemental configuration 部分,并找到以下部分(大约第 500 行),从第二行的开头删除了 #,因此该部分现在看起来像这样:

#Virtual hosts
Include conf/extra/httpd-vhosts.conf

第 4 步) 重新启动 XAMPP,现在在我的浏览器中运行它:

www.test.com

但现在我得到了这个结果:

错误无法检索请求的 URL

The following error was encountered while trying to retrieve the URL: http://test.com/

Unable to determine IP address from hostname test.com

The DNS server returned:

Name Error: The domain name does not exist.
This means that the cache was not able to resolve the hostname presented in the URL. Check if the address is correct.

Your cache administrator is root.

那么如何解决这个问题并在虚拟主机名上运行 Laravel 项目?

更新:

【问题讨论】:

  • 你的项目是用wordpress或者core php或者laravel开发的?
  • @RakeshkumarOad Laravel 5.8
  • localhost/freedeliveries你的项目是直接用这个url运行的吗?
  • @RakeshkumarOad 我不明白你的问题。我的项目目录位于xampp\htdocs` and is called freedeliveries. Because it's a Laravel project I have to run CMD and type php artiasn serve` 并在浏览器上转到localhost:8000 以加载项目。现在我需要通过在浏览器上说:www.test.com 来加载它。
  • 我的回答有问题吗?

标签: php mysql sql laravel phpmyadmin


【解决方案1】:

按照这些步骤,您将获得解决方案

1.为您的项目创建本地域:

所以你需要修改Windows的hosts文件位于

C:\Windows\System32\drivers\etc\hosts

然后在您的系统上使用自定义主机添加主机,在这种情况下,我们将使用别名“www.test.com”添加可访问的127.0.0.2 主机。

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.2 www.test.com

2.配置虚拟主机 laravel 应用程序的入口点是 public 文件夹中的 index.php,因此我们的应用程序所需的目录将是 public 文件夹中项目的绝对路径,如下例所示。 虚拟主机需要在 80 端口指向 windows 的 hosts 文件中声明的同一主机(在本例中为 127.0.0.2)。您可以创建此虚拟主机,在内容的末尾附加以下 sn -p httpd-vhosts.conf文件位于

xampp folder \xampp\apache\conf\extra

 <VirtualHost 127.0.0.2:80>
 DocumentRoot “C:/xampp/htdocs/freedeliveries/public”
 DirectoryIndex index.php
 ServerName www.test.com
 <Directory “C:/xampp/htdocs/freedeliveries/public”>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride all
 Order Deny,Allow
 Allow from all
 Require all granted
 </Directory>
 </VirtualHost>

3.从浏览器打开您的项目 最后,正如预期的那样,通过在浏览器中访问 www.test.com127.0.0.2 将显示 Laravel 应用程序的入口点:

更多详情请关注URL

端口使用问题解决方案

禁用已在运行的 FTP 服务器(很可能通过 Windows 添加/删除程序 -> Windows 功能运行)。否则,您将需要更改位于 %APPDATA%/FileZilla 的 FileZilla 设置中的端口

【讨论】:

【解决方案2】:

如果您想在项目中支持子域,则需要 DNS 服务。您可以简单地使用Acrylic DNS Service,配置设置为here

如果使用 Acrylic DNS 服务

  1. 转到亚克力用户界面
  2. 从文件打开亚克力主机>打开亚克力主机
  3. 127.0.0.1 *.test.com test.com放在主机文件的底部
  4. 从 Actions>Restart Aclyic Service 重启 DNS 服务
  5. 127.0.0.1 test.com 放在您的Windows 主机文件中

您还可以在httpd-vhosts.conf 中设置支持域的虚拟主机文件

<VirtualHost test.com:80>
    DocumentRoot "C:/xampp/htdocs/freedeliveries/public"
    ServerName test.com
    ServerAlias *.test.com
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/freedeliveries/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>    
</VirtualHost>

只需将此路由添加到/public folder 中的.htaccess 文件即可。感谢@randall 添加this answer

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

如果不使用 DNS 服务

如果你只想要www.test.com,你可以简单地将你的Windows主机文件中的主机指定为@rakesh所示的127.0.0.1 www.test.com,然后按照步骤操作。

【讨论】:

猜你喜欢
  • 2020-06-14
  • 2021-01-30
  • 2021-10-03
  • 2015-09-14
  • 2012-12-28
  • 2019-03-17
  • 2011-04-26
  • 2013-11-16
相关资源
最近更新 更多