mod_ expire
模塊配置Apache
,使網頁能在客戶端瀏覽器緩存一段時間,以免重複請求Expires
標籤和Cache-Control
標籤,從而下降客戶端的訪問頻率和次數,達到減小沒必要要的流量和增長訪問速度的目的mod_ expire
模塊/usr/local/apache/bin/apachectl -t -D DUMP_MODULES
expires_module (static)
, 則說明編譯時沒有安裝mod_expires
./configure --enable-expires...
make && make install
httpd.conf
配置文件mod_ expires
模塊, 並設置http
協議下任意格式的文檔均60
秒後過時
<lfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 60 seconds"
</lfModule>
httpd
服務Apache
服務時已經安裝過expires
模塊,這裏我直接測試[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf ...//省略部份內容... #LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so LoadModule expires_module modules/mod_expires.so //找到此模塊,去掉#開啓模塊 LoadModule headers_module modules/mod_headers.so #LoadModule unique_id_module modules/mod_unique_id.so ...//省略部份內容... <IfModule mod_expires.c> //在文件末尾處添加如下條目,對expires模塊進行配置 ExpiresActive On //開啓功能 ExpiresDefault" access plus 50 seconds" //設置緩存時間 </IfModule> :wq //保存退出 [root@localhost ~]# apachectl -t //驗證語法格式 Syntax OK //語法正常 [root@localhost ~]# service httpd stop //中止HTTP服務 [root@localhost ~]# service httpd start //啓動HTTP服務 [root@localhost ~]# /usr/local/httpd/bin/apachectl -t -D DUMP_MODULES |grep "expires" //檢測模塊是否開啓 expires_module (shared) //成功開啓 [root@localhost ~]# netstat -ntap | grep 80 //查看端口是否開啓 tcp 0 0 192.168.144.133:80 0.0.0.0:* LISTEN 47752/httpd
檢查Apache
是否安裝了mod_rewrite
模塊php
/usr/local/apache/bin/apachectl -t -D DUMP_ MODULES
rewrite_module (static)
, 則說明編譯時沒有安裝mod_ rewrite模塊./configure --enable-rewrite...
make && make install
%{HTTP_ REFERER}
: 瀏覽header
中的連接字段,存放一-個連接的URL
,表明是從哪一個連接訪問所需的網頁!^
:不之後面的字符串開頭.*$
: 以任意字符結尾NC
:不區分大寫R
:強制跳轉RewriteEngine On
: 打開網頁重寫功能RewriteCond
: 設置匹配規則RewriteRule
: 設置跳轉動做RewriteEngine On
RewriteCond %{HTTP_ REFERER} !^http://test.com/.*$ [NC]*
RewriteCond %{HTTP_ REFERER} !^http://test.com$ [NC]
RewriteCond %{HTTP_ REFERER} !^http://www.test.com/.*$ [NC]*
RewriteCond %{HTTP_ REFERER} !^http://www.test.com$ [NC]
RewriteRule .*\.(gifljipg|swf)$ http://www.test.com/error.html [R,NC]
DNS
服務,並配置DNS
服務,咱們這裏是同域名訪問網頁;在前面手工編譯安裝Apache
服務時已經安裝過放掉連模塊插件mod_rewrite
,直接進入HTTP主著配置文件進行配置。[root@localhost ~]# yum install bind -y 已加載插件:fastestmirror, langpacks base | 3.6 kB 00:00 extras | 2.9 kB 00:00 ...//省略部份內容... 已安裝: bind.x86_64 32:9.11.4-9.P2.el7 做爲依賴被安裝: bind-export-libs.x86_64 32:9.11.4-9.P2.el7 做爲依賴被升級: bind-libs.x86_64 32:9.11.4-9.P2.el7 bind-libs-lite.x86_64 32:9.11.4-9.P2.el7 bind-license.noarch 32:9.11.4-9.P2.el7 bind-utils.x86_64 32:9.11.4-9.P2.el7 dhclient.x86_64 12:4.2.5-77.el7.centos dhcp-common.x86_64 12:4.2.5-77.el7.centos dhcp-libs.x86_64 12:4.2.5-77.el7.centos 完畢! [root@localhost ~]# vim /etc/named.conf ...//省略部份內容... options { listen-on port 53 { any; }; listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; ...//省略部份內容... :wq [root@localhost ~]# vim /etc/named.rfc1912.zones ...//省略部份內容... zone "kgc.com" IN { type master; file "kgc.com.zone"; allow-update { none; }; }; ...//省略部份內容... :wq [root@localhost ~]# cd /var/named/ [root@localhost named]# ls data dynamic named.ca named.empty named.localhost named.loopback slaves [root@localhost named]# cp -p named.localhost kgc.com.zone [root@localhost named]# vim kgc.com.zone $TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 www IN A 192.168.144.133 [root@localhost named]# systemctl start named //啓動DNS服務
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf //編輯主配置文件 ...//省略部份內容... #LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so //找到此條,並開啓此條目 <IfModule unixd_module> # # If you wish httpd to run as a different user or group, you must run ...//省略部份內容... <Directory "/usr/local/httpd/htdocs"> //在此標籤下添加防盜鏈條目 # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted RewriteEngine On //開啓防盜鏈功能 RewriteCond %{HTTP_REFERER} !^http://kgc.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://kgc.com$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.kgc.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http:// www.kgc.com/$ [NC] RewriteRule .*\.(gif|jpg|swf)$ http://www.kgc.com/error.png </Directory> ...//省略部份內容... :wq [root@localhost ~]# cd /mnt //進入掛載目錄 [root@localhost mnt]# ls //查看是否有準備好的防盜鏈圖片 apr-1.6.2.tar.gz cronolog-1.6.2-14.el7.x86_64.rpm httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz apr-util-1.6.0.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt nginx-1.12.0.tar.gz awstats-7.6.tar.gz error.png miao.jpg php-5.6.11.tar.bz2 [root@localhost mnt]# cp error.png /usr/local/httpd/htdocs/ //將防盜鏈圖片複製入http站點目錄 [root@localhost mnt]# cd /usr/local/httpd/htdocs/ //進入站點目錄 [root@localhost htdocs]# ls //查看 error.png index.html miao.jpg //成功複製 [root@localhost htdocs]# systemctl start httpd //重啓網絡服務
Apache
隱藏版本信息Apache
的版本信息,透露了必定的漏洞信息,從而給網站帶來安全隱患Apache
隱藏版本信息Fiddler
抓包工具分析Apache
隱藏版本信息將主配置文件httpd.conf
如下行註釋去掉html
Include conf/extra/httpd-default.conf
httpd-default.conf
文件兩個地方ServerTokens Full
修改成Server Tokens Prod
ServersSignature On
修改成ServersSignature Off
[root@localhost htdocs]# vim /usr/local/httpd/conf/httpd.conf ...//省略部份內容... #Include conf/extra/httpd-dav.conf # Various default settings Include conf/extra/httpd-default.conf //找到此條目,並去掉註釋 # Configure mod_proxy_html to understand HTML4/XHTML1 <IfModule proxy_html_module> Include conf/extra/proxy-html.conf </IfModule> ...//省略部份內容... :wq //保存退出 [root@localhost htdocs]# cd /usr/local/httpd/conf/extra/ //進入目錄 [root@localhost extra]# ls httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf [root@localhost extra]# vim httpd-default.conf //編輯配置文件 ...//省略部份內容... # Set to one of: Full | OS | Minor | Minimal | Major | Prod # where Full conveys the most information, and Prod the least. # ServerTokens Prod //找到此條目,並更改Full爲Prod # # Optionally add a line containing the server version and virtual host # name to server-generated pages (internal error documents, FTP directory # listings, mod_status and mod_info output etc., but not CGI generated # documents or custom error documents). # Set to "EMail" to also include a mailto: link to the ServerAdmin. # Set to one of: On | Off | EMail # ServerSignature Off //並肯定此處是否爲關閉,默認爲關閉 # # HostnameLookups: Log the names of clients or just their IP addresses # e.g., www.apache.org (on) or 204.62.129.132 (off). :wq //保存退出 [root@localhost extra]# systemctl restart httpd.service //重啓服務