这里的配置使用的是命令行安装的apache,源代码安装的配置原理一样,但是配置过程不一样,大概是操作http.conf文件。
查看apache安装目录:
liang@ubuntu:~$ whereis apache2
打印如下内容,切换至apache的安装目录:
apache2: /usr/sbin/apache2 /usr/lib/apache2 /etc/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz
查看proxy模块,并且启用proxy代理模块:
liang@ubuntu:~$ cd /etc/apache2/mods-available
启用proxy代理模块:
sudo ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load
sudo ln -s /etc/apache2/mods-available/proxy_http.load /etc/apache2/mods-enabled/proxy_http.load
sudo ln -s /etc/apache2/mods-available/proxy_balancer.load /etc/apache2/mods-enabled/proxy_banancer.load
添加代理模块的配置,这里以sina与163为例进行配置:
vi /etc/apache2/sites_available/proxy
写入下面的内容:
ProxyRequests Off
ProxyVia On
UseCanonicalName Off
ProxyMaxForwards 10000
ServerAlias www.sina.com.cn
Order Deny,Allow
Allow from all
ProxyPass / http://www.sina.com.cn/
ProxyPassReverse / http://www.sina.com.cn/
ServerAlias www.163.com
Order Deny,Allow
Allow from all
ProxyPass / http://www.163.com/
ProxyPassReverse / http://www.163.com/
启用代理配置:
sudo ln -s /etc/apache2/sites_available/proxy /etc/apache2/sites_enabled/proxy
sudo /etc/init.d/apache2 restart
查看apxs工具是否安装:
liang@ubuntu:/usr/share/apache2/build$ apxs
打印如下即没有安装:
The program 'apxs' is currently not installed. You can install it by typing:
使用命令行安装:
sudo apt-get install apache2-dev
再次查看apxs工具是否安装:
liang@ubuntu:/usr/share/apache2/build$ apxs
打印如下即安装成功:
Usage: apxs -g [-S =] -n
apxs -q [-v] [-S =] [ ...]
apxs -c [-S =] [-o ] [-D [=]]
[-I ] [-L ] [-l ] [-Wc,]
[-Wl,] [-p] ...
apxs -i [-S =] [-a] [-A] [-n ] ...
apxs -e [-S =] [-a] [-A] [-n ] ...
部署修改网页的功能,去下载 mod_line_edit.c 模块源代码,mod_line_edit 可以实现网页内容修改功能,详情说明内容到mod_line_edit网站查看。
添加mod_line_edit模块:
liang@ubuntu:~/workspace/mod_line_edit$ apxs -c mod_line_edit.c
打印如下内容,提示缺少pcre支持:
/usr/share/apr-1.0/build/libtool --silent --mode=compile --tag=disable-static x86_64-linux-gnu-gcc -std=gnu99 -prefer-pic -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c -o mod_line_edit.lo mod_line_edit.c && touch mod_line_edit.slo
mod_line_edit.c:26:18: fatal error: pcre.h: No such file or directory
compilation terminated.
apxs:Error: Command failed with rc=65536
更新系统的软件源,并且安装pcre库支持:
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
再次添加mod_line_edit模块:
liang@ubuntu:~/workspace/mod_line_edit$ sudo apxs -i -a -c mod_line_edit.c
打印如下内容,即可进行下一步操作:
/usr/share/apr-1.0/build/libtool --silent --mode=compile --tag=disable-static x86_64-linux-gnu-gcc -std=gnu99 -prefer-pic -pipe -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -DLINUX -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/apache2 -I/usr/include/apr-1.0 -I/usr/include/apr-1.0 -I/usr/include -c -o mod_line_edit.lo mod_line_edit.c && touch mod_line_edit.slo
/usr/share/apr-1.0/build/libtool --silent --mode=link --tag=disable-static x86_64-linux-gnu-gcc -std=gnu99 -Wl,--as-needed -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -o mod_line_edit.la -rpath /usr/lib/apache2/modules -module -avoid-version mod_line_edit.lo
/usr/share/apache2/build/instdso.sh SH_LIBTOOL='/usr/share/apr-1.0/build/libtool' mod_line_edit.la /usr/lib/apache2/modules
/usr/share/apr-1.0/build/libtool --mode=install install mod_line_edit.la /usr/lib/apache2/modules/
libtool: install: install .libs/mod_line_edit.so /usr/lib/apache2/modules/mod_line_edit.so
libtool: install: install .libs/mod_line_edit.lai /usr/lib/apache2/modules/mod_line_edit.la
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/lib/apache2/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib/apache2/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
chmod 644 /usr/lib/apache2/modules/mod_line_edit.so
[preparing module `line_edit' in /etc/apache2/mods-available/line_edit.load]
Enabling module line_edit.
To activate the new configuration, you need to run:
service apache2 restart
配置修改网页功能,执行命令vi /etc/apache2/sites_available/proxy,编辑proxy文件,覆盖下面内容到文件中:
ProxyRequests Off
ProxyVia On
UseCanonicalName Off
ProxyMaxForwards 10000
#RequestHeader unset Accept-Encoding
ServerAlias www.sina.com.cn
Order Deny,Allow
Allow from all
ProxyPass / http://www.sina.com.cn/
ProxyPassReverse / http://www.sina.com.cn/
RequestHeader unset Accept-Encoding
SetOutputFilter line-editor
SetEnv LineEdit 'text/plain;text/css;text/html;test/javascript'
LERewriteRule photo.sina.com.cn hello.photo.sina.com.cn
ServerAlias www.163.com
Order Deny,Allow
Allow from all
ProxyPass / http://www.163.com/
ProxyPassReverse / http://www.163.com/
查看是否已经启用mod_line_edit模块:
liang@ubuntu:~/workspace/mod_line_edit$ ll /etc/apache2/mods-enabled/line_edit.load
打印如下内容,即已经启用:
lrwxrwxrwx 1 root root 32 Feb 25 13:35 /etc/apache2/mods-enabled/line_edit.load -> ../mods-available/line_edit.load
此时重启apache服务:
liang@ubuntu:~/workspace/mod_line_edit$ sudo /etc/init.d/apache2 restart
如果提示出错:
[....] Restarting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
failed!
配置了headers解析模块的功能,而没有启用该模块:
liang@ubuntu:/etc/apache2/mods-enabled$ sudo ln -s /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/headers.load
liang@ubuntu:/etc/apache2/mods-enabled$ ll /etc/apache2/mods-enabled/headers.load
打印如下内容:
lrwxrwxrwx 1 root root 40 Feb 25 13:59 /etc/apache2/mods-enabled/headers.load -> /etc/apache2/mods-available/headers.load
再次重启apache:
liang@ubuntu:~/workspace/mod_line_edit$ sudo /etc/init.d/apache2 restart
启动成功:
[ ok ] Restarting apache2 (via systemctl): apache2.service.
到此,修改网页内容的功能配置已经完成,根据第五步进行测试。其实,还有一种修改网页内容的方法,但是是针对URL的,使用模块mod_proxy_html。