Apache網頁安全最佳化

來源:互聯網
上載者:User

標籤:rewrite   編譯安裝   asc   zlib   amp   configure   require   安裝   dump   

參考手工編譯安裝Apache 安裝這些包 yum install gcc gcc-c++ make pcre pcre-devel zlib-devel -y

./configure \
--prefix=/usr/local/httpd \
--enable-deflate \ //支援可壓縮
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi

接下來 make &&make install
**修改它的設定檔 vi /etc/init.d/httpd 在檔案最前面插入下面的行

#!/bin/sh

chkconfig:2345 85 15
# description:Apache is a World Wide Web server.


給它執行許可權 chmod +x /etc/init.d/httpd

chkconfig --add httpd
chkconfig --list httpd
chkconfig --level 35 httpd on

建立軟連結 ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
vi /usr/local/apache/conf/httpd.conf 修改以下兩行
Listen:IPV4
ServerName:主機名稱.網域名稱

開啟網站服務 service httpd start
vim /etc/httpd.conf
LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so //開啟 去掉前面#
LoadModule filter_module modules/mod_filter.so
末尾添加:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript
DeflateCompressionLevel 9
SetOutputFilter DEFLATE
</IfModule>

cd /usr/local/httpd/bin
./apachectl -t
Syntax OK //驗證設定檔成功

驗證模組
./apachectl -t -D DUMP_MODULES | grep "deflate"
deflate_module (shared)

網頁緩衝 ./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-expires \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi

vim /etc/httpd.conf
LoadModule expires_module modules/mod_expires.so
末尾添加:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 50 seconds" //50s之後到期
</IfModule>

cd /usr/local/httpd/bin
./apachectl -t
Syntax OK

查看模組 ./apachectl -t -D DUMP_MODULES | grep "expires"
expires_module (shared)

**安全最佳化 yum install zlib-devel -y

./configure \
--prefix=/usr/local/httpd \
--enable-deflate \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
主設定檔修改

<Directory "/usr/local/httpd/htdocs">
Options Indexes FollowSymLinks

AllowOverride NoneRequire all granted下插入:RewriteEngine OnRewriteCond %{HTTP_REFERER} !^http://benet.com/.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://benet.com$ [NC]RewriteCond %{HTTP_REFERER} !^http://www.benet.com/.*$ [NC]RewriteCond %{HTTP_REFERER} !^http://www.benet.com/$ [NC]RewriteRule .*\.(gif|jpg|swf)$ http://www.benet.com/error.png

</Directory>

LoadModule rewrite_module modules/mod_rewrite.so //開啟

./apachectl -t -D DUMP_MODULES | grep "rewrite"
rewrite_module (shared)**

**隱藏版本資訊 Include conf/extra/httpd-default.conf 去#,開啟

vim httpd-default.conf

ServerTokens Prod //只顯示名稱,沒有版本
ServerSignature Off

**

Apache網頁安全最佳化

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.