我在Windows 7 Pro上运行XAMPP。我正在尝试设置虚拟主机,以便当我使用“dev.app”作为域时,我直接进入laravel安装的公共文件夹。
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时出现此错误
无法连接
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文件,使其在网址中具有http://dev.app
值。
已更新 添加http:// ....后,网站解析但图像未显示。
答案 0 :(得分:8)
hosts文件应该如下所示,以便可以在IPV4和IPV6网络上找到它
127.0.0.1 localhost dev.app
::1 localhost dev.app
如果您在httpd-vhosts.conf中使用Apache 2.4.x这一行
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>
答案 1 :(得分:0)
使用laragon服务器代替XAMPP。 Laragon的有用功能之一是自动病毒主机。 了解有关使用laragon here
的Pretty URL的更多信息答案 2 :(得分:0)
打开C:\ xampp \ apache \ conf \ httpd.conf,位于
#include conf / extra / httpd-vhosts.conf,在此行中删除#, 保存存档, 重新启动服务器。