[英]Permission denied with apache filter
我在 Centos7 (SELinux) 上使用 apache httpd 并尝试创建一个输出过滤器来修改所有提供的 html 页面。 我浏览了一些关于如何创建它们的教程,但在我进入编码部分之前,我一直在第一步上磕磕绊绊。
目前我在我的 httpd.conf 中有这个
ExtFilterDefine portal_header mode=output intype=text/html cmd="/var/www/root/main/portal/portal.php"
SetOutputFilter portal_header
为了查明我的问题,我暂时删除了文件 /var/www/root/main/portal/portal.php 中的所有实际代码,目前它看起来像这样
#!/usr/bin/php
<php?
/* test */
?>
但是当我知道尝试访问服务器上的任何 html 时,我收到“500 内部服务器错误”。 注释掉 httpd.conf 中的 SetOutputFilter 行后,页面工作,因此错误是由过滤器生成的。
在我的错误日志中它读取
[Fri Feb 10 14:36:55.458174 2017] [ext_filter:error] [pid 171495] (13)Permission denied: [client 10.2.8.109:49278] AH01458: couldn't create child process to run `/var/www/root/main/portal/portal.php'
[Fri Feb 10 14:36:55.458215 2017] [ext_filter:error] [pid 171495] (13)Permission denied: [client 10.2.8.109:49278] AH01467: can't initialise output filter portal_header: aborting
我至少有
但以上都没有任何影响。 唯一的变化是,当我故意拼错文件名时,我得到了“没有这样的文件或目录”错误。
有谁知道我应该怎么做才能完成这项工作? 目前我很高兴看到脚本甚至什么都不做,如果它没有损坏,然后才添加一些功能到它。
更新:我能够将问题定位到 SELinux 策略,因为在禁用它们 (setenforce 0) 后,错误消失了。 所以目前我正试图弄清楚我应该如何改变政策。
我在尝试改进一个简单的 sed 过滤器命令时遇到了类似的问题。 根据https://httpd.apache.org/docs/2.4/mod/mod_ext_filter.html文档,应该可以使用像 sed 这样的命令作为过滤器,确实可以:
以下过滤器适用于我并替换了本地链接的全局链接,以便我可以将 docker 图像与来自现有站点的数据一起使用。
# Filter configuration
# mod_ext_filter directive to define a filter which
# replaces text in the response
#
ExtFilterDefine fixtext mode=output intype=text/html \
cmd="/bin/sed s#http://ceur.ws.org#http://capri:8880#g"
<Location "/">
# core directive to cause the fixtext filter to
# be run on output
SetOutputFilter fixtext
</Location>
尝试通过访问脚本替换 sed 命令时
"cmd=/root/bin/filter.sh"
我收到错误消息:
AH01458: couldn't create child process to run `/root/bin/filter.sh'
AH01467: can't initialise output filter fixtext: aborting
这是您提出问题的最初原因。
现在我也在寻找更好的解决方案并尝试过:
cmd="/bin/bash /root/bin/filter.sh"
假设shebang解决可能是罪魁祸首。 有趣的是,我然后得到:
AH01461: apr_file_write(child input), len 0
AH01468: ef_unified_filter() failed
这就是为什么我已经发布了这个答案,希望我能尽快找到合适的解决方案,或者其他人可能会提供帮助,因为在这个问答线程 中相关的 AH014## 错误代码列表越来越长。
有关相关源代码,请参阅https://github.com/omnigroup/Apache/blob/master/httpd/modules/filters/mod_ext_filter.c 。
我假设 apr_proc_create 不能使用 shebang 调用脚本。 所以我的解决方法是
工作 apache filter.conf
# Filter configuration
# mod_ext_filter directive to define a filter which
# replaces text in the response
#
ExtFilterDefine fixtext mode=output intype=text/html \
cmd="/usr/bin/awk -f /var/www/filter.awk"
<Location "/">
# core directive to cause the fixtext filter to
# be run on output
SetOutputFilter fixtext
</Location>
工作 awk 脚本来过滤链接
# WF 2020-06-03
#
# filter HTML output thru this awk script to fix global links to local ones
#
# you might want to try out this filter from the command line with
# cat /var/www/html/index.html | awk -f filter.awk
#
# setup the replacement
BEGIN {
port=8880
host="capri"
sourceServer="http://ceur-ws.org"
targetServer=sprintf("http://%s:%s",host,port)
}
# for each line
{
# get the line
line=$0
# replace any sourceServer reference with the targetServer reference
gsub(sourceServer,targetServer,line)
# output the modified line
print line
}
/root/bin/filters.sh
#!/bin/bash
# WF 2020-06-02
# filter all html output thru this script
port=8880
host=capri
# substitute all hard links in CEUR-WS with a local link
/bin/sed s#http://ceur.ws.org#http://$host:$port#g
# try out this filter with
# cat /var/www/html/index.html | /root/bin/filter.sh | grep capri
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.