【发布时间】:2022-01-06 13:52:09
【问题描述】:
我在 Ubuntu 20.04.3 LTS 上配置了虚拟主机,但它不起作用。
首先创建的目录使用:
sudo mkdir -p /var/www/domain1.com/public_html
然后在其中创建 index.html 文件:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Welcome to domain1.com</title>
</head>
<body>
<h1>Success! domain1.com home page!</h1>
</body>
</html>
为了避免权限问题,我运行了这个命令:
sudo chown -R www-data: /var/www/domain1.com
然后在 /etc/apache2/sites-available 我创建了一个配置文件:
/etc/apache2/sites-available/domain1.com.conf
并把这段代码放进去
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
ServerAdmin webmaster@domain1.com
DocumentRoot /var/www/domain1.com/public_html
<Directory /var/www/domain1.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/domain1.com-error.log
CustomLog ${APACHE_LOG_DIR}/domain1.com-access.log combined
</VirtualHost>
然后运行这个命令:
sudo a2ensite domain1.com
然后使用命令重启apache:
sudo systemctl restart apache2
然后测试配置:
sudo apachectl configtest
并得到语法正常
的输出但是当我在浏览器中访问 domain1.com 时,得到 "This site can’t be reached" 错误。
【问题讨论】:
标签: ubuntu virtualhost ubuntu-12.04