Ubuntu 20.04下Apache子域名配置

Ubuntu 20.04下Apache子域名配置
LeKUbuntu 20.04下Apache子域名配置
系统:ubuntu 20.04
Apache版本:2.4.41
本文默认已安装好Apache和添加了子域名的DNS解析,协议类型为HTTP,主域名与子域名端口均为80
操作步骤
修改文件
1
sudo vim /etc/apache2/sites-available/000-default.conf
在文件最开始添加
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>修改和添加文件中原有的内容
1
2
3
4
5ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName parent.TopDomainName
ServerAlias parent.TopDomainName
ServerAlias *.parent.TopDomainName重启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/
评论
匿名评论隐私政策
✅ 评论时留下您的邮箱号可以获取相关评论的回复,欢迎您的指正与互动~