You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian 7服务器双虚拟主机问题:第一个已正常运行

在Debian 7上配置第二个Apache虚拟主机

先把你现有et-project.net的虚拟主机配置补全(你之前的代码截断了关键的目录权限部分),完整的可用配置应该是这样的:

<VirtualHost et-project.net:80>
    ServerAdmin webmaster@et-project.net
    ServerName et-project.net
    ServerAlias www.et-project.net
    # 网站文件目录
    DocumentRoot /var/www/et-project.net
    # 网站目录权限与选项配置
    <Directory /var/www/et-project.net/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    # 日志配置(建议保留,方便排查网站问题)
    ErrorLog ${APACHE_LOG_DIR}/et-project.net-error.log
    CustomLog ${APACHE_LOG_DIR}/et-project.net-access.log combined
</VirtualHost>

接下来咱们一步步配置第二个虚拟主机,假设你的第二个域名是example.com(你可以换成自己的实际域名):

  • 第一步:准备网站目录与测试页面
    先创建第二个网站的根目录,给Apache权限,再整个简单的测试页面确认效果:
sudo mkdir -p /var/www/example.com
sudo echo "<h1>第二个虚拟主机 example.com 已正常运行</h1>" > /var/www/example.com/index.html
sudo chown -R www-data:www-data /var/www/example.com
  • 第二步:创建第二个虚拟主机配置文件
    Debian 7的Apache虚拟主机配置文件都存在/etc/apache2/sites-available/目录下,你可以复制现有配置修改,或者新建一个:
sudo cp /etc/apache2/sites-available/et-project.net.conf /etc/apache2/sites-available/example.com.conf

然后编辑这个新的配置文件,替换成第二个域名的相关信息:

<VirtualHost example.com:80>
    ServerAdmin webmaster@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com
    <Directory /var/www/example.com/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
  • 第三步:启用配置并重启Apache
    用Apache的内置命令启用这个新配置,然后重启服务让配置生效:
sudo a2ensite example.com.conf
sudo service apache2 restart
  • 最后一步:域名解析配置
    如果是本地测试,需要修改服务器的hosts文件把域名指向本机IP:
sudo echo "你的服务器IP地址 example.com www.example.com" >> /etc/hosts

如果是公网域名,直接去你的域名服务商后台,把域名的A记录指向你的Debian服务器公网IP就可以了。

内容的提问来源于stack exchange,提问作者elderyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:06:42