This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
apache [2009/06/28 20:23] k2patel |
apache [2011/04/27 03:41] k2patel |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Apache Related Quick Help ====== | ====== Apache Related Quick Help ====== | ||
* [[ mod_evasive | DDOS Prevention module]] | * [[ mod_evasive | DDOS Prevention module]] | ||
+ | * [[ Error Codes | HTTP Error Codes ]] | ||
==== Compile apache from source ==== | ==== Compile apache from source ==== | ||
Line 34: | Line 35: | ||
<code bash> | <code bash> | ||
/srv/www/apache/bin/apxs -c -L/usr/local/lib/mysql -I/usr/local/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c | /srv/www/apache/bin/apxs -c -L/usr/local/lib/mysql -I/usr/local/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c | ||
+ | </code> | ||
+ | |||
+ | Following Error is showing up when you install it with \\ | ||
+ | |||
+ | <code bash> | ||
+ | mod_auth_mysql.c:591: error: syntax error before “mysql_auth_config_rec” | ||
+ | </code> | ||
+ | |||
+ | <code patch> | ||
+ | http://sourceforge.net/tracker/index.php?func=detail&aid=1437139&group_id=60218&atid=493464 | ||
</code> | </code> | ||
Line 75: | Line 86: | ||
RewriteEngine on | RewriteEngine on | ||
RewriteCond %{HTTP_REFERER} !^$ | RewriteCond %{HTTP_REFERER} !^$ | ||
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?xyz\.com [NC] ## Do not allow | + | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?xyz\.com [NC] ## allow |
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?pqr\.com [NC] ## Do not allow | + | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?pqr\.com [NC] ## allow |
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?abc\.org [NC] ## Do not allow | + | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?abc\.org [NC] ## allow |
- | RewriteRule \.(gif|jpe?g|png|gif|bmp|jpe|mov|mpg|avi|mpeg|jpg)$ http://www.mnr.com [NC,L] ## Allow | + | RewriteRule \.(gif|jpe?g|png|gif|bmp|jpe|mov|mpg|avi|mpeg|jpg)$ http://www.mnr.com [NC,L] ## Forward |
+ | </code> | ||
+ | |||
+ | == To enable some domain to hotlink on above list == | ||
+ | if you define above .htaccess to all your domain at global position.\\ | ||
+ | you might need to exclude some domain to allow hotlinking to it use following line after second line.\\ | ||
+ | <code apache | .htaccess> | ||
+ | RewriteCond %{HTTP_HOST} !^www\.nmn\.com$ [NC] | ||
</code> | </code> | ||
Line 130: | Line 148: | ||
<code apache | .htaccess> | <code apache | .htaccess> | ||
SetEnv TZ Europe/London | SetEnv TZ Europe/London | ||
+ | </code> | ||
+ | ==== Setup Server admin email using .htaccess ==== | ||
+ | |||
+ | To setup default notification email, you can also set based on directory. | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | ServerSignature EMail | ||
+ | SetEnv SERVER_ADMIN user@domainname.com | ||
+ | </code> | ||
+ | ==== Block request based on User Agent ==== | ||
+ | There is two way to accomplish this task. | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | SetEnvIfNoCase User-Agent "^libwww-perl" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^EmailWolf" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^ExtractorPro" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^CherryPicker" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^NICErsPRO" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^Teleport" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^EmailCollector" bad_bot | ||
+ | SetEnvIfNoCase User-Agent "^Mozilla/4\.0\ \(compatible\)$" bad_bot | ||
+ | |||
+ | Order Allow,Deny | ||
+ | Allow from all | ||
+ | Deny from env=bad_bot | ||
+ | </code> | ||
+ | |||
+ | OR | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_USER_AGENT} ^libwww-perl [OR] | ||
+ | RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR] | ||
+ | RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] | ||
+ | RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] | ||
+ | RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4\.0\ \(compatible\) [OR] | ||
+ | RewriteRule ^.* - [F,L] | ||
+ | </code> | ||
+ | |||
+ | ==== How to prevent asking for download files ==== | ||
+ | |||
+ | This will not ask you to download files. | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | AddType application/octet-stream .pdf | ||
+ | AddType application/octet-stream .zip | ||
+ | AddType application/octet-stream .mov | ||
+ | </code> | ||
+ | |||
+ | ==== Redirect Non-www to www domain ==== | ||
+ | This is useful in may stats. | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_HOST} !^www\. | ||
+ | RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] | ||
+ | </code> | ||
+ | |||
+ | ==== Redirect www to Non-www ==== | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_HOST} ^domain.com | ||
+ | RewriteRule (.*) http://www.domain.com/$1 [R=301,L] | ||
+ | </code> | ||
+ | |||
+ | ==== Redirect if HTTP_HOST not match ==== | ||
+ | |||
+ | This help you to prevent IP pointing and help gaining ranking. | ||
+ | |||
+ | <code apache | .htaccess> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_HOST} !^(.*)\.domain\.com | ||
+ | RewriteRule (.*) http://www.google.com/search?hl=en&site=domain.com&q=domain.com&btnG=Search [R=301,L] | ||
+ | </code> | ||
+ | |||
+ | ==== flv streaming + mp4 streaming with lighttpd proxy ==== | ||
+ | |||
+ | <code apache | httpd.conf> | ||
+ | ProxyRequests Off | ||
+ | ProxyPass /video http://127.0.0.1:81/ | ||
+ | ProxyPassReverse / http://127.0.0.1:81/ | ||
+ | </code> | ||
+ | |||
+ | In light httpd simply follow the configuration as usual. | ||
+ | OR | ||
+ | Check link [[lightttpd]] | ||
+ | ==== Redirect you can use with apache / lighttpd to content ==== | ||
+ | |||
+ | <code apache> | ||
+ | RewriteEngine On | ||
+ | RewriteRule ^(.*)\.(mp3|mov|mp4)$ http://www.xyz.com:81/Videos/$1.$2 [NC] | ||
+ | </code> | ||
+ | |||
+ | ==== Redirect mobile browser ==== | ||
+ | |||
+ | This will help to redirect all mobile devices to specific page. | ||
+ | |||
+ | <code apache> | ||
+ | RewriteEngine On | ||
+ | RewriteCond %{HTTP_USER_AGENT} (mobile|android|blackberry|brew|htc|j2me|lg|midp|mot|motorola|netfront|nokia|obigo|openweb|opera.mini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|vodafone|wap|webos|windows.ce) [NC] | ||
+ | RewriteRule ^(.*)$ http://ketan.lithiumfox.com/doku.php?do=search&id=htaccess [R=303,L] | ||
+ | </code> | ||
+ | |||
+ | Why 303 : | ||
+ | The response to the request can be found under another URI using a GET method. When received in response to a PUT,\\ | ||
+ | it should be assumed that the server has received the data and the redirect should be issued with a separate GET message. | ||
+ | |||
+ | |||
+ | ==== Disable Trace / track ==== | ||
+ | |||
+ | Mostly trace / track is risk to apache server.\\ | ||
+ | |||
+ | <code apache> | ||
+ | RewriteEngine on | ||
+ | RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK) | ||
+ | RewriteRule .* - [F] | ||
</code> | </code> |