我正在尝试在我的 AWS EC2 Linux 服务器上设置虚拟主机。但是,它会继续将请求定向到默认页面。
我已经安装了 apache,当我在 /var/www/html/
中创建索引文件时,它会按预期显示。
但是,当我添加一个 *.conf
虚拟主机时,它只会恢复默认页面。
我已经创建了我的 /etc/httpd/conf.d/{myvhost.conf}
文件:
<VirtualHost *:80>
DocumentRoot "/home/username/www/public"
ServerName ec2-13-55-0-7.ap-southeast-2.compute.amazonaws.com
</VirtualHost>
文档根目录已在/home/username/www/public 创建,我添加了自定义 index.html
文件,perms 设置为 755。
IncludeOptional conf.d/*.conf
在 /etc/httpd/conf/httpd.conf
重启apache。
但是显示的是默认页面,而不是我的/home/username/www/public
。
为什么?
最佳答案
首先,如果你添加一些 Directory
directives 就好了到您的根文件夹:
<Directory "/home/username/www/public/">
allow from all
Options +Indexes
</Directory>
或者(source):
<LocationMatch "^/+$">
Options Indexes
</LocationMatch>
其次,你可以debug what Apache understand of the configuration :
# Check for syntax error
apachectl -t
# List VirtualHost
apachectl -S
# both checks:
apachectl -t -D DUMP_VHOSTS
当然,检查log files .
关于linux - AWS EC2 上的 Apache VirtualHosts 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41906041/