目标: - 正确设置虚拟主机。
目前我正在研究MAC系统版本10.10.05 os x yosemite。
我使用XAMPP
配置了apache2,php和mysql我已按照all the necessary steps配置虚拟主机。
我的文件 /private/etc/apache2/extra/httpd-vhosts.conf 就像
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName emsv2l.localhost.com
ServerAlias emsv2l.localhost.com
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/emsv2"
ErrorLog "/private/var/log/apache2/apple.com-error_log"
CustomLog "/private/var/log/apache2/apple.com-access_log" common
ServerAdmin webmaster@dev.plutustec.com
<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName emsv2l-backend.plutustec.com
ServerAlias emsv2l-backend.plutustec.com
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/emsv2-backend/public“
ErrorLog "/private/var/log/apache2/apple.com-error_log"
CustomLog "/private/var/log/apache2/apple.com-access_log" common
ServerAdmin webmaster@dev.plutustec.com
<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2-backend/public“>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
所以,现在如果我写http://emsv2l.localhost.com/
将重定向到项目,而不是它显示目录结构。
我的/etc/hosts
文件就像
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
#127.0.0.1 localhost
#255.255.255.255 broadcasthost
#::1 localhost
#127.0.0.1 dev.local
#127.0.0.1 emsv2l-backend.plutustec.com # emsv2-backend
#127.0.0.1 emsv2l.plutustec.com # emsv2
#127.0.0.1 plutustec.com #localplutus site
127.0.0.1 emsv2l.localhost.com
127.0.0.1 emsv2l-backend.plutustec.com
任何帮助将不胜感激。
答案 0 :(得分:2)
您需要禁用目录列表,以替换它:
<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
使用:
<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
Options FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
然后重新加载apache 。
有关详细信息,请查看here
然后还有一件事,你在/Applications/XAMPP/xamppfiles/htdocs/emsv2
中有index.php或index.html吗?
答案 1 :(得分:1)
您是否按照指南将vhost配置为信件? 如果是这样,您确定您配置的Apache是当前正在侦听端口80的那个吗? XAMPP应该内置自己的Apache,它不会运行默认配置。 您的XAMPP httpd.conf应包含:
# XAMPP VirtualHosts dir
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
要解决最快的问题:
cp -iv /private/etc/apache2/extra/httpd-vhosts.conf /Applications/XAMPP/etc/extra/httpd-vhosts.conf
如果要求覆盖确认,请按'y'
答案 2 :(得分:0)
就我而言
我正在使用macOS Mojave(Apache / 2.4.34)。在/etc/apache2/httpd.conf文件中搜索文本“ IfModule dir_module”。检查IfModule指令/标记是否包含任何index.php。如果没有,请在index.html之后添加index.php。希望这能拯救您。
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>