繁体   English   中英

尝试使用 XAMPP 访问虚拟主机上的 Laravel 项目时无法检索请求的 URL

[英]The requested URL could not be retrieved while trying to access Laravel project on Virtual Host with XAMPP

我想用 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 向下滚动到最后的补充配置部分,并找到以下部分(大约第 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 项目呢?

更新:

在此处输入图片说明

按照以下步骤您将获得解决方案

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

所以你需要修改位于

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

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

# 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 文件夹中的绝对路径,如下例所示。 虚拟主机需要指出在windows的hosts文件中声明的同一个主机(在这个例子中是127.0.0.2)在端口80。你可以创建这个虚拟主机,在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 设置中的端口

如果你想在你的项目中支持子域,你需要一个 DNS 服务。 你可以简单地使用Acrylic DNS 服务,配置设置在这里

如果使用 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设置支持域的 vhost 文件

<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 添加此答案

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

如果不使用 DNS 服务

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM