Apache安裝配置(筆記)

#!/bin/bashyum install gcc gcc-c++ autoconf automake apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs pcre pcre-develcd /usr/local/srcwget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gztar zxvf httpd-2.4.29.tar.gzcd httpd-2.4.29./configure --prefix=/usr/local/apache -enable-module=so -enable-deflate=shared -enable-expires=shared -enable-rewrite=shared --enable-ssl --enable-rewrite \-enable-cache -enable-file-cache -enable-mem-cache -enable-disk-cache -enable-static-support -enable-static-htpasswd -enable-static-htdigest -enable-static-rotatelogs \-enable-static-logresolve -enable-static-htdbm -enable-static-ab -enable-static-checkgid -enable-cgid -enable-cgi -enable-userdir -with-mpm=worker -enable-authn-dbm=shared make&&make installcp /usr/local/apache/bin/apachectl /etc/init.d/httpdsed -i '2c\#chkconfig: 35 85 15' /etc/init.d/httpdsed -i '3c\#description: apache' /etc/init.d/httpd chmod +x /etc/init.d/httpdchkconfig --add httpdchkconfig httpd onln -s /usr/local/apache/bin/apachectl /sbin#############configvi /usr/local/apache/conf/httpd.confServerRoot "/usr/local/apache"Listen 80User wwwGroup wwwServerAdmin 13285921108@163.comServerName 192.168.10.54:80DocumentRoot "/usr/local/apache/htdocs"ErrorLog "logs/error_log"AddDefaultCharset UTF-8IncludeOptional conf/conf.d/*.confLogLevel warnHostnameLookups OffCustomLog "logs/access_log" combined###vi /usr/local/apache/conf/conf.d/test.com.confServername www.test.com,test.com

Documentroot "/usr/local/apache/htdocs/test.com"

Customlog "logs/test.com.log" combinedServername music.test.com

Documentroot "/usr/local/apache/htdocs/test.com/music"

Customlog "logs/test.com.log" combinedRequire all grantedServername book.test.com

Documentroot "/usr/local/apache/htdocs/test.com/book"

Customlog "logs/test.com.log" combinedRequire all granted#############end config#####################################################安裝模塊#################cd modulename./configure --with-apxs=/usr/local/apache/bin/apxsmakemake install##############end 安裝模塊######################################################安裝php模塊################################cd php-4.3.2./configure --with-apxs=/usr/local/apache/bin/apxsmake&&make installAddType application/x-httpd-php .php

AddHandler application/x-httpd-php .php##############end 安裝PHP模塊####################################日志格式"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""CustomLog logs/access_log combinedLogLevel Debug#記錄cookieLoadModule usertrack_module modules/mod_usertrack.soCookieStyle RFC2965

CookieTracking onCustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i"#end 記錄cookie##不記錄本機(jī)圖像請求的日志SetEnvIfNoCase Referer "^http://www.local.com/" local_referrer=1CustomLog logs/access_log combined env=!local_referrer##end 不記錄本機(jī)圖像請求的日志##以天為時(shí)間來更新日志CustomLog "| /path/rotatelogs /path/logs/access_log.%Y-%m-%d 86400" combined#######end##將活動日志記錄到MYSQL數(shù)據(jù)庫mysqladmin create apache_logmysql apache_logmysql apache_log < access_log.sqlgrant insert,create on apache_log.* to webserver@localhost identified by 'password';MySQLLoginInfo localhost webserver password

MySQLDatabase apache_log

MySQLTransferLogTable access_log

MySQLTransferLogFormat huSUsbTvRA###CustomLog | xx.sh? combined##########以端口尋址的虛擬主機(jī)Listen 8001? NameVirtualHost *:8001?

? ? ServerAdmin limingnihao@iteye.com?

? ? DocumentRoot "E:/_org.js/extjs-4.1.0/"?

? ? ServerName extjs.localhost?

? ? ErrorLog "logs/dummy-host2.localhost-error.log"?

? ? CustomLog "logs/dummy-host2.localhost-access.log" common? ?

? ? Options Indexes MultiViews?

? ? AllowOverride None?

? ? Order allow,deny?

? ? Allow from all?

Require all grantedNameVirtualHost *:80ServerName www.test1.com  DocumentRoot /www/test1/    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

  ################end############ipServerName? xxx

DocumentRoot "xxx"Order deny,allow

allow from all

Require all grantedServerName www.test1.com  DocumentRoot /www/test3/     Options Indexes FollowSymLinks

     AllowOverride None

     Order allow,deny

     Allow From All

  ###################################sslListen 443NameVirtualHost *ServerName xx.com

DocumentRoot /ss

SSLEngine On

SSLCertificateFile /xx/secure1.crt

SSLCertificateKeyFile /xx/secure1.key

ErrorLog

CustomLog xx combined##############################rewriteRewriteEngine onRewriteRule index.html index.phpRewriteRule (\d+).html$ info\.php\?infoid=$1######ErrorDocument 404 /errors/notfound.html##########配置反盜鏈RewriteEngine on#允許空“HTTP_REFERER”的訪問RewriteCond %{HTTP_REFERER} !^$ [NC] RewriteCond %{HTTP_REFERER} !nobing.cn [NC]#定義被盜鏈時(shí)替代的圖片RewriteRule .*\.(gif|jpg)$ http://nobing.cn/no.png [R,NC,L]################################配置緩存LoadModule cache_module modules/mod_cache.so LoadModule mem_cache_module modules/mod_mem_cache.so#默認(rèn)緩存有效期(秒)CacheDefaultExpire 3600 CacheMaxExpire 86400 CacheLastModifiedFactor 0.1 #禁止緩存某些特定的URL CacheDisable /local_files #使用特定的存儲類型緩存某些特定的URL CacheEnable mem /manual CacheEnable fd /images CacheEnable disk /

CacheEnable mem /

MCacheSize 8192

MCacheMaxObjectCount 10000

MCacheMinObjectSize 1

MCacheMaxObjectSize 51200

#MCacheRemovalAlgorithm LRU ##########################################/usr/local/apache/bin/apachectl -k start#start/usr/local/apache/bin/apachectl -f /usr/local/apache/conf/httpd.conf#stopkill -TERM `cat /usr/local/apache/logs/httpd.pid`apachectl -k stop#restartapachectl -k gracefulapachectl -k restartListen 80Listen 8000Listen 192.0.2.1:80Listen 192.0.2.5:8000Alias /newurl /www/htdocs/oldurl#every one has his own dirUserDir public_htmlredirect temp/permanent/seeother/goneCheckSpelling On#替換請求URL中的文字RewriteCond %{REQUEST_URI} "string1"RewriteRule "(.*)string1(.*)" "$1string2$2" [N,PT]#將路徑信息重寫至CGIRewriteEngine OnRewriteRule ^/book/([^/]*)/([^/]*) /cgi-bin/book.cgi?author=$1&subject=$2#將所有請求都重定向到httpsRewriteCond "%{SERVER_PORT}" "^80$"RewriteRule "^(.*)$" "https://%{SERVER_NAME}$1" [R,L]#將所有的請求都重定向到單一主機(jī)RewriteCond "%{HTTP_HOST}" "!^www.example.com$" [NC,OR]RewriteCond "%{SERVER_NAME}" "!^www.example.com$" [NC]RewriteRule "(.*)" "http://www.example.com$1" [R]#AuthType BasicAuthName HomeDirAuthUserFile /etc/passwdRequire valid-userSatisfy All##nginx 獲取 自定義頭部竹握,需要加上前綴 http_#限制上傳文件的大小告唆,不超過10000字節(jié)SetEnvIf Content-Length "^[1-9][0-9]{4,}" upload_too_large=1Order Deny,Allow

Deny from env=upload_too_large

ErrorDocument 403 /cgi-bin/remap-403-to-413##################################################圖片防盜鏈 SetEnvIfNoCase Referer "^http://([^/]*\.)?myserver.com/" local_referrer=1

Order Allow,Deny

Allow from env=local_referrer

#RewriteRule %{ENV:local_referrer} !=1 /Stolen-100*100.png [L]################################################在子目錄中放寬限制Satisfy AnyOrder Deny,AllowAllow from all##############################只對文件擁有者開放AuthType Basic

AuthName "MyOwnFiles"

AuthUserFile /xx

Require file-owner#########################################防止暴力破解PerLogHandler Apache::BruteWatchPerlSetVar BruteDatabase DBI:mysql:brutelogPerlSetVar BruteDataUser usernamePerlSetVar BruteDataPassword passwordPerlSetVar BruteMaxTries 5PerlSetVar BruteMaxTime 10PerlSetVar BruteNotify xx@qq.com###############################[F,NC] :禁止RewriteRule "\.(dll|zip|exe)$" protect.php [NC]##產(chǎn)生SSL證書openssl x509 -req -days 365 -in hostname.csr -signkey hostname.key -out hostname.crtSSLEngine OnSSLCertificateFile /xxx/ssl.crtSSLCertificateKeyFile /xxx/xx.key####CASSLVerifyClient requireSSLVerifyDepth 1SSLCACertificateFile conf/ssl.crt/ca.crt###nginx 常用編譯./configure --prefix=/usr/local/test/nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module? --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --add-module=/usr/local/src/nginx-1.12.2/ngx_http_substitutions_filter_module##########ScriptAlias /cgi-bin/ /www/cgi-bin/Alias /cgi-bin/ /www/cgi-bin/? Options ExecCGI

? SetHandler cgi-script? Options +ExecCGI

? AddHandler cgi-script .cgi .py .pl##自己的CGI程序Action watermark /cgi-bin/watermark.cgiAddHandler watermark .gif .jpg##Options +IncludesErrorDocument 405 /errors/notallowed.html###防止代理服務(wù)器被作為開放式的郵件轉(zhuǎn)發(fā)工具? RewriteEngine On

? RewriteRule "^proxy:[a-z]*://[^/]*:25(/|$)" "-" [F,NC,L]ProxyPass /other/ http://other.server.com/ProxyPassReverse /other/ http://other.server.com/ProxyBlock www.xx.com? xx.com#將服務(wù)器設(shè)為代理服務(wù)器迈窟,并高速緩存ProxyRequests onCacheRoot /var/spool/httpd/proxy###############過濾mod_ext_filterExtFilterDefine naughtywords mode=output intype=text/html cmd="/bin/sed s/darned/blasted/g"SetOutputFilter naughtywords####################對代理服務(wù)器進(jìn)行身份驗(yàn)證###########性能MaxClients 125? 最多處理125個(gè)進(jìn)程ab -n 1000 -c 10 http://www.xx.comKeepAlive OnMaxKeepAliveRequests 0KeepAliveTimeout 15##服務(wù)器狀態(tài)SetHandler server-statusExtendedStatus On######HostnameLookups off;AllowOverride None;NMapFileCacheFile--enable-file_cacheOptions +IndexesDirectoryIndex

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末镰官,一起剝皮案震驚了整個(gè)濱河市宵晚,隨后出現(xiàn)的幾起案子李茫,更是在濱河造成了極大的恐慌规辱,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,454評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件疚沐,死亡現(xiàn)場離奇詭異暂氯,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)濒旦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,553評論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來再登,“玉大人尔邓,你說我怎么就攤上這事晾剖。” “怎么了梯嗽?”我有些...
    開封第一講書人閱讀 157,921評論 0 348
  • 文/不壞的土叔 我叫張陵齿尽,是天一觀的道長。 經(jīng)常有香客問我灯节,道長循头,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,648評論 1 284
  • 正文 為了忘掉前任炎疆,我火速辦了婚禮卡骂,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘形入。我一直安慰自己全跨,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,770評論 6 386
  • 文/花漫 我一把揭開白布亿遂。 她就那樣靜靜地躺著浓若,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蛇数。 梳的紋絲不亂的頭發(fā)上挪钓,一...
    開封第一講書人閱讀 49,950評論 1 291
  • 那天,我揣著相機(jī)與錄音耳舅,去河邊找鬼碌上。 笑死,一個(gè)胖子當(dāng)著我的面吹牛挽放,可吹牛的內(nèi)容都是我干的绍赛。 我是一名探鬼主播,決...
    沈念sama閱讀 39,090評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼辑畦,長吁一口氣:“原來是場噩夢啊……” “哼吗蚌!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起纯出,我...
    開封第一講書人閱讀 37,817評論 0 268
  • 序言:老撾萬榮一對情侶失蹤蚯妇,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后暂筝,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體箩言,經(jīng)...
    沈念sama閱讀 44,275評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,592評論 2 327
  • 正文 我和宋清朗相戀三年焕襟,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了陨收。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,724評論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖务漩,靈堂內(nèi)的尸體忽然破棺而出拄衰,到底是詐尸還是另有隱情,我是刑警寧澤饵骨,帶...
    沈念sama閱讀 34,409評論 4 333
  • 正文 年R本政府宣布翘悉,位于F島的核電站,受9級特大地震影響居触,放射性物質(zhì)發(fā)生泄漏妖混。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,052評論 3 316
  • 文/蒙蒙 一轮洋、第九天 我趴在偏房一處隱蔽的房頂上張望制市。 院中可真熱鬧,春花似錦砖瞧、人聲如沸息堂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,815評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽荣堰。三九已至,卻和暖如春竭翠,著一層夾襖步出監(jiān)牢的瞬間振坚,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,043評論 1 266
  • 我被黑心中介騙來泰國打工斋扰, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留渡八,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,503評論 2 361
  • 正文 我出身青樓传货,卻偏偏與公主長得像屎鳍,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子问裕,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,627評論 2 350

推薦閱讀更多精彩內(nèi)容