[英]In Linux configuring virtual host and localhost redirecting to the xampp folder
[英]configuring virtual host and localhost redirecting to the xampp folder
我在创建虚拟主机时遇到问题。 我正在使用 Windows 7 x64 专业版。 在文件C:\\Windows\\System32\\drivers\\etc\\hosts
我只有这一行:
127.0.0.1 myhost
127.0.0.1 www.myhost
在文件C:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf
我有这个:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Users/Me/Dropbox/Project/public"
ServerName myhost
ServerAlias www.myhost
<Directory "C:/Users/Me/Dropbox/Project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
当然,在这些文件中添加这一行后,我已经重新启动了我的 Apache 服务器。 不幸的是,在浏览器中输入myhost
或www.myhost
将我重定向到myhost/xampp
。
我已经搜索过,并且在 google 和 stackoverflow 上找到了如何使用 xampp 配置虚拟主机的描述,但是我怎么知道我已经完成了一切。 我知道我的问题并不新鲜,但我没有找到适合我的解决方案。
我也意识到在浏览器中输入localhost
也会重定向我localhost/xampp
。 我不知道这些问题是否与我的情况有关。
我有同样的问题。 您的第一个请求是重定向到 htdocs 根目录。 如果您查看 htdocs 目录中的 index.php,您会看到非常简短的代码,它接收传入的请求并将其重定向到 xampp 目录。
我通过摆弄 httpd-vhosts.conf 文件修复了它。 在您的情况下,请尝试进行以下编辑:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\xampp\htdocs\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "C:\Users\Me\Dropbox\Project\public"
ServerName www.myhost
ServerAlias www.myhost
<Directory "C:\Users\Me\Dropbox\Project\public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我有一个类似的问题,发现我必须转到我的 Apache24 主 httpd.conf 文件并在第 501 行“Include conf/extra/httpd-vhost.conf”周围取消注释我以前从未使用过它,它仍然是 #'ed出去。 希望这有助于任何在这里找不到其他答案的人。 我的 Apache24 现在可以看到我的 vhost 文件。
您需要启用基于名称的虚拟主机。
靠近 C:\\xampp\\apache\\conf\\extra\\httpd-vhosts 中的文件顶部
取消注释#NameVirtualHost *:80
即来自:
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
到:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
(注意最后一行现在没有注释)。
对我来说就像一种魅力。 :)
试试这个
[文件:C:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf]
<VirtualHost basic.test:80>
DocumentRoot "C:/xampp/htdocs/basic/public/"
ServerName basic.test
</VirtualHost>
[文件:C:\\Windows\\System32\\drivers\\etc\\hosts](以管理员身份打开)
127.0.0.1 basic.test
127.0.0.1 localhost
对我来说,将这个<VirtualHost *:80>
替换为这个<VirtualHost 127.0.0.1:80>
工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.