[英]How to enable Virtual Host on Xampp for Laravel?
我在 Windows 7 Pro 上运行 XAMPP。 我正在尝试设置一个虚拟主机,以便当我使用“dev.app”作为域时,我可以直接进入 laravel 安装的公共文件夹。
Laravel 位于F:/xampp/htdocs/dev/public
我打开了位于F:\\xamp\\apache\\conf\\extra\\https-vhosts.conf
的httpd-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 时,出现此错误
无法连接
Firefox 无法与 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 文件,以在 url 中包含http://dev.app
值。
添加 http://.. 后更新。网站解析但图像未显示。
主机文件应如下所示,以便可以在 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>
使用 laragon 服务器而不是 XAMPP。 Laragon 的一项有用功能是 Auto Virutal Hosts。 在此处了解有关 laragon 的漂亮 URL 的更多信息
`打开C:\\xampp\\apache\\conf\\httpd.conf,定位到
#Include conf/extra/httpd-vhosts.conf,去掉#这一行,保存文件,重启服务器`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.