gpt4 book ai didi

apache - 如何在 Xampp 上为 Laravel 启用虚拟主机?

转载 作者:行者123 更新时间:2023-12-04 10:49:17 24 4
gpt4 key购买 nike

我在 Windows 7 Pro 上运行 XAMPP。我正在尝试设置一个虚拟主机,以便当我使用“dev.app”作为域时,我可以直接进入我的 laravel 安装公共(public)文件夹。

Laravel 位于 F:/xampp/htdocs/dev/public
我打开了httpd-vhosts.conf文件位于 F:\xamp\apache\conf\extra\https-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 localhost>
DocumentRoot "F:/xampp/htdocs/"
ServerAdmin admin@localhost

<Directory "F:/xampp/htdocs/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>

</VirtualHost>

# Development
<VirtualHost dev.app>
DocumentRoot "F:/xampp/htdocs/dev/public"
ServerAdmin admin@localhost

<Directory "F:/xampp/htdocs/dev/public">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>

然后我打开了位于 C:\Windows\System32\drivers\etc 的主机文件并添加将 localhost 行更改为如下所示
127.0.0.1       localhost      dev.app
127.0.0.1 127.0.0.1

但是,当我在浏览器中访问 dev.app 时出现此错误

Unable to connect

Firefox can't establish a connection to the server at app.dev.

The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.


我在这里想念什么?
我做错什么了?

注:更改 vhosts 文件后,我重新启动了 Apache。另外,我将 laravel config 文件夹中的 app.php 文件更新为 http://dev.app url 中的值。

更新
添加 http://.... 后,该站点解析但图像未显示。

最佳答案

hosts 文件应如下所示,以便可以在 IPV4 和 IPV6 网络上找到它

127.0.0.1  localhost dev.app
::1 localhost dev.app

如果您使用的是 Apache 2.4.x, 中的这一行httpd-vhosts.conf
NameVirtualHost *:80

Apache 2.4 不再需要或允许。

vhost 文件应该是这样的,你混合了 Apache 2.2 和 2.4 的语法,只要你有 mod_access_compat 任何一个都是允许的。激活,你不应该混合它们,2.4的语法更好。你还错过了一些其他有用的点点滴滴
<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/"
ServerAdmin admin@localhost
ServerName localhost

<Directory "F:/xampp/htdocs/">
Options Indexes FollowSymLinks
AllowOverride all
Require local
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "F:/xampp/htdocs/dev/public"
ServerAdmin admin@localhost
ServerName dev.app
ServerAlias www.dev.app

<Directory "F:/xampp/htdocs/dev/public">
AllowOverride All
Options Indexes FollowSymLinks

Require local
# if you want access from other pc's on your local network
#Require ip 192.168.1
# Only if you want the world to see your site
#Require all granted
</Directory>
</VirtualHost>

关于apache - 如何在 Xampp 上为 Laravel 启用虚拟主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31951931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com