Ubuntu 20.04下Apache子域名配置

Ubuntu 20.04下Apache子域名配置


系统:ubuntu 20.04

Apache版本:2.4.41

本文默认已安装好Apache和添加了子域名的DNS解析,协议类型为HTTP,主域名与子域名端口均为80

操作步骤

  1. 修改文件

    1
    sudo vim /etc/apache2/sites-available/000-default.conf
  2. 在文件最开始添加

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <VirtualHost *:80>
    ServerName sub.parent.TopDomainName
    ServerAlias sub.parent.TopDomainName
    ServerAlias *.sub.parent.TopDomainName
    DocumentRoot /your/root/path
    <Directory /your/root/path>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    allow from all
    Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/sub.error.log
    CustomLog ${APACHE_LOG_DIR}/sub.access.log combined
    </VirtualHost>
  3. 修改和添加文件中原有的内容

    1
    2
    3
    4
    5
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ServerName parent.TopDomainName
    ServerAlias parent.TopDomainName
    ServerAlias *.parent.TopDomainName
  4. 重启Apache

    1
    sudo systemctl restart apache2

参考链接

https://serverfault.com/questions/940764/multiple-subdomains-apache-2-4

https://www.jianshu.com/p/a9eeac672069

https://codeleading.com/article/3320567975/

https://blog.csdn.net/u011350810/article/details/132321027

https://blog.csdn.net/zuosiran001/article/details/117487566