Enable Gzip Compression in Apache

This is a simple sample configuration for the impatient.

Compress only a few types

AddOutputFilterByType DEFLATE text/html text/plain text/xml

The following configuration, while resulting in more compressed content, is also much more complicated. Do not use this unless you fully understand all the configuration details.

Compress everything except images

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

 

 

 

ref: Apache Doc

nJoy 😉

 

Allowing Apache to see client ip from Behind a trusted proxy.

With high speed caching based on nginx, varnish or CDNs in general the client ip gets lost. All
IPs get reported as 127.0.0.1 since the proxy is making the socket request. Solution is two phased:

1) enable reporting the client IP to the X-Forwarded-For header at the proxy or CDN.

This depends on the proxy will be covered in separate posts.

2) installing and configuring the mod_remoteip in Apache 2.

 

Project link L https://github.com/ttkzw/mod_remoteip-httpd22
mkdir /usr/local/src/mod_remoteip
cd /usr/local/src/mod_remoteip
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.c
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/mod_remoteip.conf
wget https://raw.githubusercontent.com/ttkzw/mod_remoteip-httpd22/master/Makefile

yum install httpd-devel
make
make install

Configuration in the Apache config file:

in /etc/httpd/conf/httpd.conf

# Load and configure mod_remoteip for Google PageSpeed Service
LoadModule remoteip_module /usr/lib64/httpd/modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For

service apache reload

voila 🙂

Measuring Apache bandwidth from a bash script

So reason : double checking Sawmill and AWstats.

(sawmill won..)

echo “$(awk ‘{print $10}’ prd.logs | grep -v “-” | paste -sd + – | bc )/1024/1024/1024″ | bc

result is in GB.

nJoy;

 

Using .htaccess to redirect a page with permanently moved 301

Though there are many ways to redirect using the HTTP 301 status code.

(make sure the AllowOverride is set to all on the apache config)

The .htaccess must be as follows:

Options +FollowSymlinks
 RewriteEngine on
 rewritecond %{http_host} ^orig.domain.com [nc]
 rewriterule ^(.*)$ http://new.domain.com/
 $1 [r=301,nc]

Replace the orig.domain.com and new.domain.com with the ones needed for your case of course.

You can setup logs for checking the rewriting though be warned enable them only when debugging they are hugely intensive on I/O and CPU on a heavy utilised server.

More info here : http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog