Ubuntu apache多站点配置

学习自Linux公社 Ubuntu/CentOS下Apache多站点配置

Apache多站点配置

前言

我自己在阿里云上买了acmlzq.cn域名,现在我想在阿里云服务器上搭建多个网站,比如一个博客(blog.acmlzq.cn),一个云盘(pan.acmlzq.cn),那么就需要多站点配置

搭建过程

我的环境

Ubuntu:Ubuntu16.04 LTS
apache:Apache/2.4.18(apache2 -v命令查看)

修改流程

Apache主配置文件为/etc/apache2/apache2.conf,打开之后会发现最后两行为:

    # Include the virtual host configurations:
    IncludeOptional sites-enabled/*.conf

意味着/etc/apache2/sites-enabled下存放着虚拟站点的配置,切换到/etc/apache2/sites-enabled后,会发现该目录下有一个软链接

    000-default.conf -> ../sites-available/000-default.conf

这里又引出了另一个配置目录:/etc/apache2/sites-available,这个目录存放着真正的配置文件。

第一步:新增站点配置文件

在/etc/apache2/sites-available目录中建立站点配置文件wordpress.conf

<VirtualHost *:80>
        ServerAdmin acmlzq@qq.com
        ServerName blog.acmlzq.cn
        DocumentRoot /var/www/html/wordpress
        
        <Directory "var/www/html/wordpress">
                Options FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

ServerName,DocumentRoot,Directory为重点关注的配置点,ServerName为域名,DocumentRoot、Directory为根目录。

第二步:在sites-enabled目录下建立符号链接

    sudo ln -s /etc/apache2/sites-available/wordpress.conf /etc/apache2/sites-enabled/wordpress.conf

第三步:修改/etc/hosts文件

打开/etc/hosts文件,开头是:

127.0.0.1 localhost

在该行后面添加:

127.0.0.1 blog.acmlzq.cn

保存退出

重启apache服务器并测试

    service apache2 restart

打开浏览器查看或者命令行测试:

    curl blog.acmlzq.cn
posted @ 2019-07-20 14:43  黑色的夢  阅读(891)  评论(0)    收藏  举报