修改apache配置文件vim /etc/httpd/conf/httpd.conf
Alias /webapp "/root/home/webapps"
<Directory "/root/home/webapps">
# Options FollowSymLinks
# AllowOverride None
# Order allow,deny
# Deny from all
# Allow from all
Require all granted
</Directory>
重启httpd
service httpd restart
测试:curl http://127.0.0.1/webapp/test.html
老是出现问题,没有访问权限, 查看错误日志,配置文件中配置的错误日志路径是/etc/httpd/conf/logs/error_log
运行命令:tail error_log
Permission denied: [client 127.0.0.1:46930] AH00035: access to /webapp/test.html denied (filesystem path '/root/home') because search permissions are missing on a component of the path
是root或者home文件对www组没有设置rx权限
运行命令chmod o+rx root, chmode o+rx home
重启后还是出错禁止访问错误:
AH01797: client denied by server configuration: /root/home/webapps/test.html
把Directory节点下的其他配置都注释掉,只留下 Require all granted
Alias /webapp "/root/home/webapps"
<Directory "/root/home/webapps">
# Options FollowSymLinks
# AllowOverride None
# Order allow,deny
# Deny from all
# Allow from all
Require all granted
</Directory>
重启httpd,终于能成功访问了。
由于我的CentOS是装在VB虚拟机中的,想在windows7中访问,配置VB的端口映射,81---》80,访问不了,应该是防火墙的原因,关闭防火墙
service firewalld stop
OK啦
注:有些linux开启了selinux的,还是禁止访问的
getenforece 查询selinux状态
selinux有三种状态
enforcing: 强制开启
permissive:允许执行,但要打印警告
disabled: 关闭
临时关闭selinux
setenforce 0
永久关闭
reboot后生效