Search This Blog

Loading...

10.24.2007

Apache cheat sheet

# Setup a Virtual Domain
NameVirtualHost *

DocumentRoot /web/example.com/www
ServerName www.example.com
ServerAlias example.com
CustomLog /web/example.com/logs/access.log combined
ErrorLog /web/example.com/logs/error.log




# Include another conf file
Include /etc/apache/virtual-hosts/*.conf

# Hide apache version info
ServerSignature Off
ServerTokens Prod
Custom 404 Error message
ErrorDocument 404 /404.html

#Create a virtual directory (mod_alias)
Alias /common /web/common

#Perminant redirect (mod_alias)
Redirect permanent /old http://example.com/new

#Hide apache version infoCreate a cgi-bin
ScriptAlias /cgi-bin/ /web/cgi-bin/

Process .cgi scripts
AddHandler cgi-script .cgi

#Add a directory index
DirectoryIndex index.cfm index.cfm

#Turn off directory browsing
Options -Indexes
#Turn on directory browsing

#When applying directives to objects that reside in the filesystem always use or . When applying directives to objects that do not reside in the filesystem (such as a webpage generated from a database), use .


Options +Indexes

Create a new user for basic auth (command line)
htpasswd -c /etc/apacheusers
#Apache basic authentication
AuthName "Authentication Required"
AuthType Basic
AuthUserFile /etc/apacheusers

Require valid-user





#Only allow access from a specific IP



Order Deny,Allow
Deny from all
Allow from 127.0.0.1



Only allow access from your subnet
Order Deny,Allow
Deny from all
Allow from 176.16.0.0/16

mod_rewrite
#Turn on the rewrite engine
RewriteEngine On
# Redirect /news/123 to /news.cfm?id=123

# Flags

# [NC] No case sensitive
# [OR] Allows multiple lines
# [R=#] Redirect where # is number: 404.
# [L] Terminate routine

# . Every char
# < > = Compare
# \ Escape a char
# .+ One more, more chars
# .* No chars or multiple chars
# ^ Start
# $ End
# (…) Group
# a|b .A or B
# (a|b) .A or B group
# a{5} Exact 5 times a
# a{1,5} Between 1 and 5 times a
# [a-z]* Match chars
# -d Directory
# -f File
# -l Symbolic link



RewriteRule ^/news/([0-9]+)$ /news.cfm?id=$1 [PT,L]

#Redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]



#add apache user -b pass to the command line

htpasswd - b GroupToAddTo FirstNameLastName theVarySecretPass

Apache reads only on startup the its conf file

Add Apache to the startup (check you version of *x

# ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S57apache



Redirect all visitors except for those with User-Agent header starts with Googlebot from www.oxit.fi to oxit.fi

RewriteCond %{HTTP_USER_AGENT} !^Googlebot/
RewriteCond %{HTTP_HOST} ^www\.oxit\.fi

RewriteRule ^(.*)$ http://oxit.fi$1 [R=301]




Order allow,deny
Deny from all


RewriteRule ^(.*/)?\.secret/ - [F,L]

RedirectMatch 404 /\.secret(/|$)

10.19.2007

perl oneliners

#Perl OneLiners Cheat Sheet

# run contents of "my_file" as a program
perl my_file

# run debugger "stand-alone"
perl -d -e 42

# run program, but with warnings
perl -w my_file

# run program under debugger
perl -d my_file

# just check syntax, with warnings
perl -wc my_file

# useful at end of "find foo -print"
perl -nle unlink

# add first and penultimate columns
perl -lane 'print $F[0] + $F[-2]'

# just lines 15 to 17
perl -ne 'print if 15 .. 17' *.pod

# in-place edit of *.c files changing all foo to bar
perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c

# command-line that prints the first 50 lines (cheaply)
perl -pe 'exit if $. > 50' f1 f2 f3 ...

# delete first 10 lines
perl -i.old -ne 'print unless 1 .. 10' foo.txt

# change all the isolated oldvar occurrences to newvar
perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]

# command-line that reverses the whole file by lines
perl -e 'print reverse <>' file1 file2 file3 ....

# find palindromes
perl -lne 'print if $_ eq reverse' /usr/dict/words

# command-line that reverse all the bytes in a file
perl -0777e 'print scalar reverse <>' f1 f2 f3 ...

# command-line that reverses the whole file by paragraphs
perl -00 -e 'print reverse <>' file1 file2 file3 ....

# increment all numbers found in these files
perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....

# command-line that shows each line with its characters backwards
perl -nle 'print scalar reverse $_' file1 file2 file3 ....

# delete all but lines beween START and END
perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt

# binary edit (careful!)
perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape

# look for dup words
perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi'



#convert html to text
cat index.htm | perl -ne 's/\<[^<]*\>//g ;print $_'

10.16.2007

Apache cheat sheet

# Setup a Virtual Domain
NameVirtualHost *

DocumentRoot /web/example.com/www
ServerName www.example.com
ServerAlias example.com
CustomLog /web/example.com/logs/access.log combined
ErrorLog /web/example.com/logs/error.log




# Include another conf file
Include /etc/apache/virtual-hosts/*.conf

# Hide apache version info
ServerSignature Off
ServerTokens Prod
Custom 404 Error message
ErrorDocument 404 /404.html

#Create a virtual directory (mod_alias)
Alias /common /web/common

#Perminant redirect (mod_alias)
Redirect permanent /old http://example.com/new

#Hide apache version infoCreate a cgi-bin
ScriptAlias /cgi-bin/ /web/cgi-bin/

Process .cgi scripts
AddHandler cgi-script .cgi

#Add a directory index
DirectoryIndex index.cfm index.cfm

#Turn off directory browsing
Options -Indexes
Turn on directory browsing

Options +Indexes

Create a new user for basic auth (command line)
htpasswd -c /etc/apacheusers
#Apache basic authentication
AuthName "Authentication Required"
AuthType Basic
AuthUserFile /etc/apacheusers

Require valid-user





Only allow access from a specific IP
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Only allow access from your subnet
Order Deny,Allow
Deny from all
Allow from 176.16.0.0/16

mod_rewrite
#Turn on the rewrite engine
RewriteEngine On
# Redirect /news/123 to /news.cfm?id=123

# Flags

# [NC] No case sensitive
# [OR] Allows multiple lines
# [R=#] Redirect where # is number: 404.
# [L] Terminate routine

# . Every char
# < > = Compare
# \ Escape a char
# .+ One more, more chars
# .* No chars or multiple chars
# ^ Start
# $ End
# (…) Group
# a|b .A or B
# (a|b) .A or B group
# a{5} Exact 5 times a
# a{1,5} Between 1 and 5 times a
# [a-z]* Match chars
# -d Directory
# -f File
# -l Symbolic link



RewriteRule ^/news/([0-9]+)$ /news.cfm?id=$1 [PT,L]

#Redirect www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]



#add apache user -b pass to the command line

htpasswd - b GroupToAddTo FirstNameLastName theVarySecretPass

Blog Archive

My Blog List

Video Bar

Loading...

About Me

My Photo
Yordan Georgiev
It is one thing to know what to want, second to really want it, third to know how to do it, fourth to be skillful to do it, fifth to actually do it and last but not least to go on without regrets after having done it. LinkedIn Profile
View my complete profile