如何在Ubuntu 15上的Apache服务器上配置虚拟主机

问题描述 投票:0回答:1

我正在为我的本地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正常工作。当我处理其他网站时,我收到“请求的网址未找到”错误。更奇怪的是,当我输入“localhost”或“home.dev”时,我得到同一页面。这不应该发生。要清楚,其他任何网站都不起作用。我以phpMyAdmin网站为例。以下是一些配置文件的列表。任何人都可以给我一个什么是错的线索?

/etc/Apache2/sites-available/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/sites-available/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/sites-available/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
php apache ubuntu configuration virtualhost
1个回答
2
投票

您必须启用虚拟主机配置,尝试这样做

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>
© www.soinside.com 2019 - 2024. All rights reserved.