Detailed Apache configuration image anti-theft chain and hidden version information

Source: Internet
Author: User

Brief introduction

Anti-theft chain is to prevent other people's website code inside the stolen server image, file, video and other related resources

Experimental environment
    • System Environment: CentOS6.5
    • Related source package: Baidu Cloud download?? Password: PKO3
IP Address Domain name Use
192.168.100.103 Www.bt.com SOURCE Host
192.168.100.104 Www.test.com Hotlinking website
Build step one, prepare for work 1, close the firewall and SELinux

[Email protected] ~]# chkconfig iptables off #随开机关闭iptables
[Email protected] ~]# Vim/etc/sysconfig/selinux

[email protected] ~]# reboot #重启生效

2. Uninstall to install httpd related package in RPM mode

[Email protected] ~]# Rpm-qa | grep "httpd"

[email protected] ~]# Yum remove httpd #卸载httpd相关包

3. Build a DNS server

If you don't have a friend for the above two services, check out my other posts for more information
http://blog.51cto.com/11905606/2156944

Second, build httpd service 1, install GCC, gcc-c++, make, ARP, Arp-util, Pcre and other toolkits

[Email protected] ~]# yum-y install gcc gcc-c++ make Zlib-devel #安装C语言编译器以及make

[Email protected] ~]# TAR-ZXVF apr-1.4.6.tar.gz-c/usr/src/
[Email protected] ~]# cd/usr/src/apr-1.4.6/
[[email protected] apr-1.4.6]#./configure prefix=/usr/local/apr && make && make install

[Email protected] ~]# TAR-ZXVF apr-util-1.4.1.tar.gz-c/usr/src/
[Email protected] ~]# CD/USR/SRC/APR-UTIL-1.4.1/
[Email protected] apr-util-1.4.1]#/configure prefix=/usr/local/apr-util--with-apr=/usr/local/apr && Make & amp;& make Install

[Email protected] ~]# TAR-ZXVF pcre-8.10.tar.gz-c/usr/src #支持正则
[Email protected] ~]# cd/usr/src/pcre-8.10/
[[email protected] pcre-8.10]#./configure prefix=/usr/local/pcre && make && make install

2, configure the compilation installation httpd

[Email protected] ~]# tar zxvf httpd-2.4.2.tar.gz-c/usr/src/
[Email protected] ~]# cd/usr/src/httpd-2.4.2/
[Email protected] httpd-2.4.2]#/configure \
--PREFIX=/USR/LOCAL/HTTPD \
--WITH-APR=/USR/LOCAL/APR \
--with-pcre=/usr/local/pcre \
--enable-deflate \
--ENABLE-SO \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi

parameter resolution:

Prefix: Specifying the installation directory
Enable-deflate: Enable Mod_deflate module
ENABLE-SO: Enable dynamic load module support, what functions are required to dynamically load
Enable-rewrite: Enable Web address rewriting to implement pseudo-static
Enable-charset-lite: Default Character Set
Enable-cgid: Enable Cgid

[[email protected] httpd-2.4.2]# make && make install #编译及编译安装

3. Adding system Services

[Email protected] ~]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD

[Email protected] ~]# VIM/ETC/INIT.D/HTTPD

lines 2nd, 32 add the following parameters:

# chkconfig:2345 85 15
# Description:apache is a world Wide Web server.

[Email protected] init.d]# chmod +x/etc/init.d/httpd
[Email protected] init.d]# chkconfig--add httpd

4, the establishment of soft links, easy to manage

[Email protected] ~]# mkdir-p/etc/httpd
[Email protected] ~]# ln-s/usr/local/httpd/conf//etc/httpd/#优化配置文件路径
[Email protected] ~]# ln-s/usr/local/httpd/bin/*/usr/local/bin/#优化命令路径

5. Modify the configuration file

[Email protected] ~]# vim/etc/httpd/conf/httpd.conf

Modify the following parameters:

ServerName www.bt.com:80 #填写完全主机名
Listen 192.168.100.103:80 #监听本地IP

6. Start httpd Service

[[Email protected] ~]# service httpd start
[Email protected] ~]# NETSTAT-ANPT | grep ': 80 '

Three, Analog hotlinking 1, edit the source host test page

[email protected] ~]# CP logo.jpg error.jpg/usr/local/httpd/htdocs/#将测试图片拷贝到http站点目录中
[Email protected] ~]# cd/usr/local/httpd/htdocs/#进入站点目录
[Email protected] htdocs]# vim index.html #编辑默认首页

?? <body>
???? ???? #首页添加图片
?? </body>

2. Access test source host test page

3, test hotlinking website misappropriation source host picture

[Email protected] ~]# cd/usr/local/httpd/htdocs/#进入盗链主机站点目录
[Email protected] htdocs]# vim index.html #编辑默认首页
?? <body>
???? ???? #注意使用的源主机的图片地址
?? </body>

4, visit Test hotlinking website Testing page

Four, the source host configuration anti-theft chain 1, modify the master configuration file

[Email protected] ~]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件
LoadModule rewrite_module modules/mod_rewrite.so #约146行, turn on the rewrite function module

Modify edit the following parameters about 213 lines

DocumentRoot "/usr/local/httpd/htdocs"
<directory "/usr/local/httpd/htdocs" > #定义的站点目录
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Rewriteengine on
Rewritecond% (http_referer)!^HTTP://BT.COM/.*$[NC]
Rewritecond% (http_referer)!^HTTP://BT.COM$[NC]
Rewritecond% (http_referer)!^HTTP://WWW.BT.COM/.*$[NC]
Rewritecond% (http_referer)!^HTTP://WWW.BT.COM$[NC]
Rewriterule. *. (gif|jpg|swf) $ http://www.bt.com/error.png
</Directory>

Configuration Rule Variable Description:

(The picture in which directory, in which directory to do the special set of anti-theft chain)
%{http_referer}: Browse the Link field in the header to hold a linked URL that represents the link from which to access the desired page
!^: Do not start with the following string
. *$: End With any character
NC: Uppercase Not distinguished
R: Force Jump

Rule Matching Description:

Rewriteengine on: Open Web page rewriting feature
Rewritecond: Setting matching rules
Rewriterule: Set Jump action
Rule matching: If the value of the corresponding variable matches the rule set, it is processed down-by-down, and if it does not match, the subsequent rule no longer matches

2. Restart HTTPD Service

[Email protected] ~]# httpd-t

[[email protected] ~]#/etc/init.d/httpd Restart # restart HTTPD service

[Email protected] ~]# apachectl-t-D dump_modules | grep ' rewrite '

3. Test hotlinking

V. Configuring hidden version information 1, pre-modification capture package test

2. Modify the master configuration file

[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
Include conf/extra/httpd-default.conf #约477行, turn on default configuration

3. Modify the default configuration file

[Email protected] ~]# vim/etc/httpd/conf/extra/httpd-default.conf

Servertokens Prod #约55行 The default parameter is to display all the full information and change the value to Prod (short message)
Serversignature off #约65行 default is off, the server version is turned off and the service is being served servername

4. Restart HTTPD Service

[Email protected] ~]#/etc/init.d/httpd restart

5. Catch the package test again

Detailed Apache configuration image anti-theft chain and hidden version information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.