#!/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##不记录本机图像请求的日志SetEnvIfNoCase Referer "^http://www.local.com/" local_referrer=1CustomLog logs/access_log combined env=!local_referrer##end 不记录本机图像请求的日志##以天为时间来更新日志CustomLog "| /path/rotatelogs /path/logs/access_log.%Y-%m-%d 86400" combined#######end##将活动日志记录到MYSQL数据库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##########以端口寻址的虚拟主机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]#定义被盗链时替代的图片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#默认缓存有效期(秒)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]#将所有的请求都重定向到单一主机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字节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]##产生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###防止代理服务器被作为开放式的邮件转发工具 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#将服务器设为代理服务器,并高速缓存ProxyRequests onCacheRoot /var/spool/httpd/proxy###############过滤mod_ext_filterExtFilterDefine naughtywords mode=output intype=text/html cmd="/bin/sed s/darned/blasted/g"SetOutputFilter naughtywords####################对代理服务器进行身份验证###########性能MaxClients 125 最多处理125个进程ab -n 1000 -c 10 http://www.xx.comKeepAlive OnMaxKeepAliveRequests 0KeepAliveTimeout 15##服务器状态SetHandler server-statusExtendedStatus On######HostnameLookups off;AllowOverride None;NMapFileCacheFile--enable-file_cacheOptions +IndexesDirectoryIndex