如何配置好httpd

首先明确目地:

1、使用web页面调用shell脚本;

2、web访问时拥有root权限;

3、通过web使用需要tty终端的命令。


一、安装httpd

为了使apache使用root执行命令,需按以下步骤安装:


1、卸载系统默认安装的apr、apr-util

rpm -e  --allmatches --nodeps apr-util

rpm -e  --allmatches --nodeps apr


2、安装apr

tar  zxvf  apr-1.4.6.tar.gz

cd  apr-1.4.6

./configure

make

make install

echo "/usr/local/apr/lib" >>/etc/ld.so.conf

ldconfig


2、安装apr-util

tar  zxvf  apr-util-1.5.1.tar.gz

cd  apr-util-1.5.1

./configure --with-apr=/usr/local/apr

make

make install

(安装时可能报错,可尝试安装expat-devel)

yum install  -y expat-devel


3、安装pcre

tar  zxvf  pcre-8.21.tar.gz

cd  pcre-8.21

./configure --with-apr=/usr/local/apr

make

make install


4、安装httpd

tar zxvf  httpd-2.4.3.tar.gz

cd  httpd-2.4.3

修改Apache 源代码,在 include/http_config.h  头部中自行添加如下语句

#ifndef BIG_SECURITY_HOLE

#define BIG_SECURITY_HOLE

#endif

./configure --prefix=/usr/local/httpd --enable-ssl --enable-cgi --enable-mods-shared=allable-ssl --enable-cgi --enable-mods-shared=all  --enable-track-vars --enable-rewrite 

make

make install


(安装报错解决办法)

如安装时提示openssl版本过低,可按此教程升级

apache2.4以上版本 make报错[exports.lo] Error 1 解决方法

64位Linux下源码安装apache2


二、配置httpd

1、编辑httpd.conf

cd    /usr/local/httpd/conf


增加root权限:

User root

Group root


如web调用shell时直接显示脚本代码,在配置文件中去除注释:

LoadModule cgi_module /usr/lib/apache2/modules/mod_cgi.so

LoadModule cgi_module /usr/lib/apache2/modules/mod_cgid.so


安全优化:

添加允许访问的ip或用户名  httpd页面用户访问认证控制


重启apache

/usr/local/httpd/bin/apachectl start|stop


三、 创建shell脚本和web接口

1、创建shell脚本

cd /cgi-bin/

vim shell

#!/bin/sh

alias urldecode='sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"'

echo -e "Content-type: text/plain\n"

decoded_str=`echo $QUERY_STRING | urldecode`

echo -e "`$decoded_str` \n"

chmod +x shell


2、创建web接口

cd /htdocs

vim index.html

<html>

<script><head>

function httpGet(url)

{ var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", url, false); 

xmlHttp.send(null); return xmlHttp.responseText; }

function f()

{ var url = "http://127.0.0.1/cgi-bin/shell?"+ document.getElementById('in').value;

document.getElementById('out').innerHTML = httpGet(url); }

</script></head>

<body>

<span>command:</span>

<input id='in'></input>

<button onclick='f()'>send</button>

<br/>

<pre id='out'></pre>

</body>

</html>


3、允许脚本执行需要tty终端的命令

vi /etc/sudoers  

注释掉 Default requiretty 一行

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容