详述Linux系统中Apache网页与安全优化(二)

发布时间:2020-08-06 00:02:29 作者:SiceLc
来源:网络 阅读:3109

网页缓存

配置网页的缓存时间

启用网页缓存功能步骤

查看是否安装了mod_ expire模块

如果没有安装则要重新编译安装

修改httpd.conf配置文件

重启httpd服务

再次访问测试网站,使用抓包工具Fiddler进行数据抓取分析

配置实例

[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安全优化

配置防盗链

配置Apache实现防盗链

配置规则变量说明

规则匹配说明

规则匹配

配置操作演示

配置实例

[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隐藏版本信息

重启httpd服务,访问网站,抓包测试

配置实例

[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   //重启服务
推荐阅读:
  1. Apache网页优化与安全优化(网页压缩;网页缓存;网页防盗
  2. Apache网页优化—网页压缩

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

apache linux http he inux

上一篇:php获取远程网站图片并保存本地

下一篇:InnoDB Online DDL一瞥

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》