我在 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"
错误。
最佳答案
您已将 Apache 配置为特殊情况,它接收到的任何请求 domain1.com
你没有:
(或者使用类似
hosts
的文件进行本地破解)。
关于ubuntu - 虚拟主机 UBUNTU 显示无法访问此站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70608154/