环境
OS:CentOS 6.7
httpd:Server version: Apache/2.2.15 (Unix)
我的需求
暴露81端口,映射操作系统中/data/swagger文件夹(该文件夹是一个静态WEB)。
遇到问题
启动httpd之后,访问ip:81,总是报Apache 2 Test Page powered by CentOS。
解决方案
找了很久,说是把SELinux的状态改一下就可以。
https://stackoverflow.com/questions/14726931/virtual-host-showing-apache-test-page-and-everything-else-in-doc-root-is-forbidd
执行setenforce 0
总结
一定要学会看日志!出了问题,首先就要想到看人家的日志!日志啊,README,配置中的注释,官网文档啊,这些都是重点。以前也有接触过SELinux,基础不牢,今天愣是没想起来。后来查看日志/etc/httpd/logs/error_log,才发现里边一直有报
[Wed Mar 01 13:01:21 2017] [error] [client 192.168.233.1] (13)Permission denied: access to /index.html denied
[Wed Mar 01 13:06:47 2017] [notice] caught SIGTERM, shutting down
[Wed Mar 01 13:06:47 2017] [notice] SELinux policy enabled; httpd running as context unconfined_u:system_r:httpd_t:s0
[Wed Mar 01 13:06:47 2017] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Mar 01 13:06:47 2017] [notice] Digest: generating secret for digest authentication ...
我的配置(我将初始的httpd.conf备份成httpd.confbak,对比两文件)
[root@localhost conf]# diff httpd.conf httpd.confbak
137c137
< Listen 6080
---
>
276c276
< ServerName localhost:80
---
> #ServerName www.example.com:80
317c317
< <Directory "/data/swagger">
---
> <Directory "/var/www/html">
1010,1016d1009
<
< <VirtualHost 192.168.233.233:6080>
< DocumentRoot /data/swagger
< Header set Access-Control-Allow-Origin *
< ServerName 192.168.233.233:6080
< </VirtualHost>
<
SELinux
//todo