繁体   English   中英

在 Debian 7 上设置 apache 虚拟主机

[英]Setup an apache Virtual Hosts on Debian 7

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

应用步骤

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

得到的结果

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

Server_IP/newsite.com/httpdocs

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

编辑:

配置文件内容:

<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>

您需要在这里考虑几件事:

  1. 如果您尝试访问 newsite.com,您需要确保有适当的 DNS 记录,或者将域和 IP 添加到您的主机文件中。

  2. 你的<Directory>标签应该是<Directory /var/www/newsite.com/httpdocs>

  3. 确保你的 apache 配置中有NameVirtualHost *:80 ,这通常会在 Debian 上的ports.conf中。 如果没有这个,apache 将服务于默认的虚拟主机,听起来就像你必须输入newsite.com/httpdocs来查看你的内容一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM