Get the App
SLTechnology News&Howtos  ›  Servers  › 

Optimization of Apache service with one click of Shell script

Shulou Source: shulou.com Published: 2022-06-03 02:49:24 09月22日 Update

Use Shell script to optimize Apache service with one click (including log segmentation, log file analysis system, static resource compression, setting web cache time, hotlink protection, system version number hiding)

This experiment uses a collection of software packages (all open source software): link: https://pan.baidu.com/s/1Byuu3PWgCap85lqfqrA6eA extraction code: x806 please add a link description

Installation steps: manually compile and install apache → install dns service → for log segmentation → install log file analysis system → to compress static resources → facility web cache time → hotlink protection setting → version number hiding

#! / bin/bashyum install bind expect-y # install basic DNS and expect Interactive Free read-p "provide IP for hard disk:" ipsmbclient-L / / $ip/ > / var/named/zhy.zone#DNS configuration http= "/ usr/local/httpd/conf/httpd.conf" sed-I-e'/ Listen 80/s/ ^ / # /'- e "/ # Listen 12.34.56.78:80/s/#Listen 12.34.56.78:80/Listen $zhu: 80 / "$httpsed-I'/ # ServerName www.example.com/s/#ServerName www.example.com/ServerName www.zhy.com/' $httpcd / usr/local/httpd/bin/./apachectl startsed-I'/ ErrorLog\" logs\ / error_log\ "/ s/ErrorLog\" logs\ / error_log\ "/ ErrorLog\"\ |\ / usr\ / sbin\ / cronolog logs\ / www.zhy.com.error_\% Y\% d.log\ "/'$httpsed- I'/ CustomLog\ "logs\ / access_log\" common/s/CustomLog\ "logs\ / access_log\" common/CustomLog\ "\ |\ / usr\ / sbin\ / cronolog logs\ / www.zhy.com.access_\% Y\% m\% d.log\" combined/' $http#HTTP service changes monitoring, Change the domain name ln-s / usr/local/httpd/bin/* / etc/init.d/ service apachectl stopservice apachectl start# log partition cd / mnttar zxf awstats-7.6.tar.gzmv awstats-7.6 / usr/local/awstatscd / usr/local/awstats/tools/expect > / etc/crontabecho "* / 5 * root / usr/local/awstats/tools/awstats_updateall.pl now" > > / etc/crontab/bin/systemctl reload crond.servicesystemctl enable crond# creation plan Touch / usr/local/httpd/htdocs/houtai.htmlecho "> > / usr/local/httpd/htdocs/houtai.htmlecho" > > / usr/local/httpd/htdocs/houtai.htmlecho "> / usr/local/httpd/htdocs/houtai.htmlecho" > > / usr/local/httpd/htdocs/houtai.htmlservice apachectl stopservice apachectl startsystemctl stop firewalld.service Setenforce 0systemctl start named# log file segmentation system cd / mntsed-I'/ LoadModule deflate_ module modules\ / mod_ deflate.so/s/#/ /'$httpecho "" > > $httpecho "AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript" > $httpecho "DeflateCompressionLevel 9" > > $httpecho "SetOutputFilter DEFLATE" > > $httpecho "> > $http# static resource compression sed-I'/ LoadModule expires_module/s/#/ /'$httpecho" > > $httpecho " ExpiresActive On "> $httpecho" ExpiresDefault\ "access plus 30 seconds\" > $httpecho "> > $http# Page caching time sed-I'/ LoadModule rewrite_module/s/#/ /'$httpsed-I '248a RewriteEngine On\ nRewriteCond% {HTTP_REFERER}! ^ http://zhy.com/.*$ [NC]\ n RewriteCond% {HTTP_REFERER}! ^ http://zhy.com$ [NC]\ n RewriteCond% {HTTP_REFERER}! ^ http:// Www.zhy.com/.*$ [NC]\ nRewriteCond% {HTTP_REFERER}! ^ http://www.zhy.com/$ [NC]\ nRewriteRule. *\\. (gif | jpg | swf) $https://cache.yisu.com/upload/information/20200309/28/16809.jpg' $http# hotlink protection Please put the anti-theft image in the default site htdocs sed-I'/ httpd-default.conf/s/#/ /'$httpdefault= "/ usr/local/httpd/conf/extra/httpd-default.conf" sed-I '55s and FullUniverse' $default# hidden version number service apachectl stopservice apachectl startecho "Native IP is: $zhu"

Tags: Logs systems security services files times versions caches web pages resources static software links analysis compilation scripts one-click success tasks pictures Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia macOS MariaDB Huawei Apple