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ī)圖像請(qǐng)求的日志SetEnvIfNoCase Referer "^http://www.local.com/" local_referrer=1CustomLog logs/access_log combined env=!local_referrer##end 不記錄本機(jī)圖像請(qǐng)求的日志##以天為時(shí)間來(lái)更新日志CustomLog "| /path/rotatelogs /path/logs/access_log.%Y-%m-%d 86400" combined#######end##將活動(dòng)日志記錄到MYSQL數(shù)據(jù)庫(kù)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”的訪問(wèn)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 #使用特定的存儲(chǔ)類型緩存某些特定的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#替換請(qǐng)求URL中的文字RewriteCond %{REQUEST_URI} "string1"RewriteRule "(.*)string1(.*)" "$1string2$2" [N,PT]#將路徑信息重寫(xiě)至CGIRewriteEngine OnRewriteRule ^/book/([^/]*)/([^/]*) /cgi-bin/book.cgi?author=$1&subject=$2#將所有請(qǐng)求都重定向到httpsRewriteCond "%{SERVER_PORT}" "^80$"RewriteRule "^(.*)$" "https://%{SERVER_NAME}$1" [R,L]#將所有的請(qǐng)求都重定向到單一主機(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_#限制上傳文件的大小,不超過(guò)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##############################只對(duì)文件擁有者開(kāi)放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證書(shū)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ù)器被作為開(kāi)放式的郵件轉(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###############過(guò)濾mod_ext_filterExtFilterDefine naughtywords mode=output intype=text/html cmd="/bin/sed s/darned/blasted/g"SetOutputFilter naughtywords####################對(duì)代理服務(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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容