美文网首页
Ubuntu apache2配置虚拟主机

Ubuntu apache2配置虚拟主机

作者: 请叫我老曹 | 来源:发表于2018-02-03 12:31 被阅读0次

    示例环境

    • 根据自己的环境查看。
      IP:192.168.0.108
      域名:www.tp5.com
      目录:/home/error/www/html/tp5test

    一、在/etc/hosts下添加

    sudo vim /etc/hosts
    添加
    192.168.0.108 www.tp5.com
    
    hosts.png

    二、在/etc/apache2/sites-available目录下创建test.conf

    sudo cp /etc/apache2/sites-availabel/000-default.conf /etc/apache2/sites-availabel/test.conf
    

    三、修改test.conf文件

    vim /etc/apache2/sites-availabel/test.conf
    修改为
    <VirtualHost *:80>
            ServerName www.tp5.com
            ServerAdmin webmaster@localhost
            DocumentRoot /home/error/www/html/tp5test
    </VirtualHost>
    

    四、启动配置

    1、建立关联

    sudo ln -s /etc/apache2/sites-availabel/test.conf /etc/apache2/sites-enabled/
    或
    sudo a2ensite /etc/apache2/sites-availabel/test.conf
    

    2、重新启动apache2

    sudo /etc/init.d apache2 restart
    或
    sudo service apache2 restart
    

    五、想要在windows上访问还需要设置

    1、打开C:\Windows\System32\drivers\etc\hosts

    添加
    192.168.0.108 www.tp5.com
    

    如图

    ven.png

    相关文章

      网友评论

          本文标题:Ubuntu apache2配置虚拟主机

          本文链接:https://www.haomeiwen.com/subject/zpkuzxtx.html