This shows you the differences between two versions of the page.
apache [2009/06/28 20:23] k2patel |
apache [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Apache Related Quick Help ====== | ||
- | * [[ mod_evasive | DDOS Prevention module]] | ||
- | ==== Compile apache from source ==== | ||
- | Good known required configuration | ||
- | <code bash | apache 2.x> | ||
- | ./configure --prefix=/srv/www --enable-access --enable-autoindex --enable-env --enable-info --enable-mime --enable-proxy --enable-status --enable-usertrack --enable-actions --enable-imap --enable-log_agent --enable-rewrite --enable-alias --enable-auth --enable-cgi --enable-dir --enable-include --enable-log_config --enable-mime_magic --enable-negotiation --enable-setenvif --enable-userdir --enable-define --enable-log_forensic --enable-ssl --enable-so --enable-dav | ||
- | </code> | ||
- | |||
- | ==== Dynamic DocumentRoot for Sub-Domains with RewriteEngine/RewriteCond/RewriteRule ==== | ||
- | |||
- | <code apache> | ||
- | <VirtualHost *> | ||
- | ServerAlias www.yourdomain.com | ||
- | ServerName www.yourdomain.com | ||
- | RewriteEngine on | ||
- | RewriteCond %{HTTP_HOST} ^yourdomain.com | ||
- | RewriteRule ^(.*)$ /www/$1 [L] | ||
- | RewriteCond %{HTTP_HOST} ^www.* | ||
- | RewriteRule ^(.*)$ /www/$1 [L] | ||
- | RewriteCond %{HTTP_HOST} ^(.*)\.yourdomain\.com | ||
- | RewriteRule ^(.*)$ /%1/$1 [L] | ||
- | </VirtualHost> | ||
- | </code> | ||
- | |||
- | ==== Broken Image rewrite ==== | ||
- | |||
- | <code apache> | ||
- | RewriteCond %{REQUEST_FILENAME} !-f | ||
- | RewriteRule \.(gif|jpg|png)$ http://www.xyz.com/images/broken_image.jpg [R=301,L] | ||
- | </code> | ||
- | |||
- | ==== mod_auth_mysql installation ==== | ||
- | <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 | ||
- | </code> | ||
- | |||
- | ==== phpinfo() Based on Location ==== | ||
- | |||
- | <code apache> | ||
- | Alias /php-info /usr/local/apache/libexec/info.php | ||
- | <Location /php-info> | ||
- | AuthUserFile /usr/local/apache/libexec/info.pw | ||
- | AuthGroupFile /dev/null | ||
- | AuthType Basic | ||
- | AuthName "PHP Info" | ||
- | require valid-user | ||
- | </Location> | ||
- | </code> | ||
- | |||
- | ==== Location Based Password ==== | ||
- | <code apache> | ||
- | <Location /stats/> | ||
- | AuthUserFile /usr/local/www/statspass | ||
- | AuthName "Stats Admin" | ||
- | AuthType Basic | ||
- | Require valid-user | ||
- | </Location> | ||
- | </code> | ||
- | |||
- | ==== Disable mod_security for specific folder using .htaccess ==== | ||
- | <code apache | .htaccess> | ||
- | SecFilterEngine Off | ||
- | SecFilterScanPOST Off | ||
- | </code> | ||
- | |||
- | ==== How to run php from cgi-bin folder ==== | ||
- | <code apache> | ||
- | Action php-script /cgi-bin/php | ||
- | AddHandler php-script .php | ||
- | </code> | ||
- | |||
- | ==== How to Disable Hotlinking using .htaccess ==== | ||
- | <code apache | .htaccess> | ||
- | RewriteEngine on | ||
- | RewriteCond %{HTTP_REFERER} !^$ | ||
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?xyz\.com [NC] ## Do not allow | ||
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?pqr\.com [NC] ## Do not allow | ||
- | RewriteCond %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?abc\.org [NC] ## Do not allow | ||
- | RewriteRule \.(gif|jpe?g|png|gif|bmp|jpe|mov|mpg|avi|mpeg|jpg)$ http://www.mnr.com [NC,L] ## Allow | ||
- | </code> | ||
- | |||
- | ==== Block IP using .htaccess ==== | ||
- | <code apache | .htaccess> | ||
- | <Limit GET POST> | ||
- | order allow,deny | ||
- | allow from all | ||
- | deny from .microsoft.com | ||
- | deny from .evil-hackers.org | ||
- | deny from 24.112.106.235 | ||
- | deny from morphine.wiretap.net | ||
- | </Limit> | ||
- | </code> | ||
- | ==== How to test mod_perl === | ||
- | <code perl> | ||
- | #!/usr/local/bin/perl | ||
- | |||
- | $www = $ENV{'SERVER_PORT'} ne ""; | ||
- | eval "use Compress::Zlib"; $hasCompress = $@ ? 0 : 1; | ||
- | eval "use LWP"; $hasLWP = $@ ? 0 : 1; | ||
- | eval "use LWP::Simple"; $hasLWPsimple = $@ ? 0 : 1; | ||
- | if ($hasLWPsimple) { | ||
- | eval "use LWP::UserAgent"; | ||
- | my $ua = LWP::UserAgent->new(timeout => 30); | ||
- | $u = "http://www.c3scripts.com/test/test.txt"; | ||
- | $resp = $ua->request(HTTP::Request->new('GET', $u)); | ||
- | $okLWP = $resp->content =~ /test\.pl/i; | ||
- | } | ||
- | eval "use CGI::Carp qw(fatalsToBrowser)"; $hasCGI = $@ ? 0 : 1; | ||
- | $w = 16; $f = "<b>%" . $w . "s</b> : %s\n"; $f2 = " " x $w . " & %s\n"; | ||
- | print "Content-type: text/html\n\n<html><body><pre>" if ($www); | ||
- | printf $f, "test.pl", "v6.01.18"; | ||
- | printf $f, "Perl", "v$]"; | ||
- | printf $f, "CGI::Carp", ($hasCGI? "" : "not ") . "installed"; | ||
- | printf $f, "Compress::Zlib", ($hasCompress? "" : "not ") . "installed"; | ||
- | printf $f, "LWP", ($hasLWP? "v$LWP::VERSION " : "not ") . "installed"; | ||
- | printf $f, "LWP::Simple", ($hasLWPsimple? "" : "not ") . "installed"; | ||
- | printf $f, "LWP::Simple", "rx " . ($okLWP? "" : "not ") . "ok" if ($hasLWPsimple); | ||
- | printf $f, "\@INC", $INC[0]; foreach $x (1..$#INC) { printf $f2, $INC[$x];} | ||
- | foreach $x (sort split(",", | ||
- | "DOCUMENT_ROOT,SCRIPT_FILENAME,PATH_INFO,PATH_TRANSLATED,". | ||
- | "REQUEST_FILENAME,HTTP_HOST,SERVER_SOFTWARE")) | ||
- | { printf $f, $x, $ENV{$x} } | ||
- | print "</pre></body></html>\n" if ($www); | ||
- | 1; | ||
- | </code> | ||
- | ==== Setting Timezone using .htaccess ==== | ||
- | you can setup timezone using setting environment using TZ. | ||
- | |||
- | <code apache | .htaccess> | ||
- | SetEnv TZ Europe/London | ||
- | </code> |