在Debian 7上设置apache虚拟主机

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

我尝试在新的debian 7安装上设置一个apache虚拟主机,如下所示:

applied steps

1.安装apache服务器:

apt-get install apache2

2.创建我的新目录:

mkdir -p /var/www/newsite.com/httpdocs

3.授予虚拟主机所需的权限

chown -R $USER:$USER /var/www/newsite.com/httpdocs

chmod -R 755 /var/www

4.创建一个简单的索引文件来测试结果:

nano /var/www/newsite.com/httpdocs/index.html

5.启用网站:

   cp /etc/apache2/sites-available/default /etc/apache2/sites-available/newsite.com

打开新配置文件进行编辑:

nano /etc/apache2/sites-available/newsite.com

添加ServerName,ServerAlias和DocumentRoot:

ServerName newsite.com
ServerAlias www.newsite.com
DocumentRoot /var/www/newsite.com/httpdocs

激活主机:

a2ensite newsite.com

然后重启apache:

service apache2 restart

obtained result

我现在可以通过Web浏览器访问我的索引文件,但只有当我输入时:

Server_IP/newsite.com/httpdocs

Question

我想通过在我的Web浏览器中输入newsite.com来直接访问我的虚拟主机,实现这一目标缺少了什么步骤,并且可以指向特定文件(index.html或index.php)作为默认启动文件虚拟主机?

EDIT:

配置文件的内容:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName newsite.com
        ServerAlias www.newsite.com
        DocumentRoot /var/www/newsite.com/httpdocs
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
apache debian virtualhost
1个回答
0
投票

这里你需要考虑的几件事情:

  1. 如果您尝试访问newsite.com,则需要确保存在相应的DNS记录,或者将域和IP添加到hosts文件中。
  2. 你的<Directory>标签应该是<Directory /var/www/newsite.com/httpdocs>
  3. 确保你的apache配置中有NameVirtualHost *:80,这通常会在Debian上的ports.conf中找到。如果没有这个,apache将服务于默认的虚拟主机,它听起来像是在做,因为您必须键入newsite.com/httpdocs才能看到您的内容。
© www.soinside.com 2019 - 2024. All rights reserved.