我正在为本地Apache环境设置一些虚拟主机。我将此作为基本指南:http://www.unixmen.com/setup-apache-virtual-hosts-on-ubuntu-15-10/
目前,我的结构如下:/var/www/home
-这里有一个脚本,它在"sites"目录中查找,并为"sites)目录中的每个文件夹生成一个带有按钮的页面/var/www/sites
-所有站点都存储在此处。
我的home.dev指向/var/www/home,localhost指向/var/www/sites
(因此,如果需要,我可以键入localhost/site1)
问题是只有localhost和home.dev才能正常工作。当我寻址其他网站时,我会收到"未找到请求的URL"错误。更奇怪的是,当我键入"localhost"或"home.dev.时,我会得到相同的页面。这不应该发生。需要明确的是,其他网站都不起作用。我以phpMyAdmin站点为例。以下是一些配置文件的列表。有人能告诉我出了什么问题吗?
/etc/apache2/可用站点/home.conf
<VirtualHost *:80>
ServerName www.home.dev
ServerAlias home.dev
DocumentRoot /var/www/home/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/home>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/apache2/站点可用/localhost.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/sites/
<Directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sites>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/apache2/站点可用/phpmyadmin.dev.conf
<VirtualHost *:80>
ServerName phpmyadmin.dev
ServerAlias phpmyadmin.dev
DocumentRoot /var/www/sites/phpmyadmin
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sites/phpmyadmin>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/hosts
127.0.0.1 localhost
127.0.1.1 userman-desktop
127.0.2.1 home.dev
127.0.3.1 phpmyadmin.dev
127.0.5.1 sites.dev
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
您必须启用虚拟主机配置,要做到这一点,请尝试类似的方法
sudo ln -s /etc/apache2/sites-available/home.conf /etc/apache2/sites-enable/
sudo ln -s /etc/apache2/sites-available/phpmyadmin.dev.conf /etc/apache2/sites-enable/
sudo ln -s /etc/apache2/sites-available/localhost.conf /etc/apache2/sites-enable/
然后重新启动apache服务
sudo service apache2 restart
并且您的/etc/hosts应该是
127.0.0.1 localhost
127.0.0.1 userman-desktop
127.0.0.1 home.dev
127.0.0.1 phpmyadmin.dev
127.0.0.1 sites.dev
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
和home.conf
<VirtualHost *:80>
ServerName home.dev #<--- change this
ServerAlias home.dev
DocumentRoot /var/www/home/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/home>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>