且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

docker centos7 httpd的小坑

更新时间:2022-09-25 17:37:24

我的寄主机是centos6.7  3.10的内核  今天下了个镜像做docker docker容器竟然是centos7  我也是醉了


这里说下在apache简单配置里面的坑  , 由于是验证没有较多的配置 只是想实现echo hello的效果


apache是yum安装的   完事没有发现/etc/init.d/httpd脚本 也是 7都改版了  可是

systemctl start httpd.service也是不好用的

我发现安装了个命令 httpd  在/usr/sbin 下


执行httpd  报错

[root@d9706c29a233 /]# httpd

AH00526: Syntax error on line 119 of /etc/httpd/conf/httpd.conf:

DocumentRoot must be a directory

docker centos7 httpd的小坑

119行是 DocumentRoot "/var/www/html"  没有路径


解决办法

mkdir -p /var/www/html

chown apache:apache !$


然后执行报错:

[root@d9706c29a233 /]# httpd

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6. Set the 'ServerName' directive globally to suppress this message

(2)No such file or directory: AH02291: Cannot access directory '/etc/httpd/logs/' for main error log

AH00014: Configuration check failed

docker centos7 httpd的小坑

大概意思是servername不对  和 没有路径 /etc/httpd/logs


把  #ServerName www.example.com:80   修改为 ServerName localhost:80

sed -i 's@#ServerName www.example.com@ServerName localhost@' /etc/httpd/conf/httpd.conf  


/etc/httpd/logs -> /var/log/httpd  软连接  只需要创建/var/log/httpd 就可以了

mkdir /var/log/httpd 

chown apache:apache !$

echo 'hello' > /var/www/html/index.html



再次启动

httpd  

curl 127.0.0.1

访问成功

本文转自    憬薇   51CTO博客,原文链接:http://blog.51cto.com/welcomeweb/1713948