Results 1 to 7 of 7
  1. #1

    Default Save bandwidth by using mod_deflate

    Hitting your bandwidth quota every month? Want to know how to save bandwidth? Just enable mod_deflate, it is already installed onto your account you just need to enable it.
    The file we will be working with is /etc/httpd/conf/httpd.conf, once you open it for editing you will want to look for this line:
    Code:
    <Directory "/var/www/html">
    once you have found that line, just a few lines below it, you should see this line:
    Code:
    </Directory>
    All you need to do is add this line BEFORE the </Directory> tag
    Code:
    AddOutputFilterByType DEFLATE text/html text/css text/xml text/plain text/javascript application/x-javascript application/xml application/xhtml+xml application/postscript
    Mine now looks like this:

    Code:
    <Directory "/var/www/html">
        Options FollowSymLinks Includes
        AddHandler cgi-script .cgi .pl .py .sh
        AllowOverride All
        Order allow,deny
        Allow from all
        AddOutputFilterByType DEFLATE text/html text/css text/xml text/plain text/javascript application/x-javascript application/xml application/xhtml+xml application/postscript
    </Directory>
    then save and restart the account by either using the Restart Account from the Site Manager or using
    Code:
    apachectl restart
    from a shell

    What that line does is define types that should be compressed. The types that are listed in there are the most common that will compress nicely, most other file types such as images, video, etc do not compress well and all it will do is slow down your video feed, images, etc.

    If you have subdomains or secondary domains that you want to add this to as well, just find the virtual host entry that looks like (yours will look different)
    Code:
    <VirtualHost *:80>
        ServerName blog.dattasmoon.com
        ServerAlias www.blog.dattasmoon.com
        DocumentRoot /var/www/blog
    </VirtualHost>
    First we need to add a directory tag in the virtual host entry:
    Code:
    <Directory (SAME PATH AS  DocumentRoot GOES HERE)>
    </Directory>
    and we do the same thing as we did for the primary site, so mine now looks like:

    Code:
    <VirtualHost *:80>
        ServerName blog.dattasmoon.com
        ServerAlias www.blog.dattasmoon.com
        DocumentRoot /var/www/blog
        <Directory /var/www/blog>
            AddOutputFilterByType DEFLATE text/html text/css text/xml text/plain text/javascript application/x-javascript application/xml application/xhtml+xml application/postscript
        </Directory>   
    </VirtualHost>
    Then just restart apache using one of the methods described above.
    Depending on your content (like my blog is mostly text so I see about 80% bandwidth savings on it), you can see anywhere from 10% - 80% bandwidth savings!
    Want me to make a tutorial on how to install something? PM me!
    Got questions? Just reply below.
    Last edited by dattas; 07-19-2008 at 09:43 AM.
    Unofficial technical support for the world.

  2. #2

    Default

    The AddOutputFilterByType DEFLATE line can actually be added directly to httpd.conf, outside of any directives. This will cause Apache to compress ALL requests from any directory and any virtual host.

    You may also wish to add the line SetInputFilter DEFLATE, which allows Apache to accept compressed input from the browser.

  3. #3

    Default

    Every little bit helps! Thanx for this tip!

  4. #4

    Default

    Does this also deflate PHP output as well? I can't remember how PHP is output, but I'm guessing text/html.

  5. #5

    Default

    Yes, this applies to ALL output. Since PHP and Perl scripts are executed first, then passed through Apache, their output will also be compressed using this method as long as they output an appropriate Content-Type header. By default, all PHP documents are output as type text/html so they would be compressed.

  6. #6

    Default

    Has anyone considered the CPU hit of doing this?

    Bandwidth is dirt cheap but CPU is extremely limited by comparison. Especially on a hosted environment like this.

    It's been a while since I've looked, but I remember seeing something about pre-compressing all of your image and other static files. Then you send them out compressed and never incur the CPU hit. It also saves in disk space locally. For the rare time that the client doesn't accept compressed data, you can configure the server to decompress the file before it sends(which if memory serves is a much lower overhead then compression)

    Scott

  7. #7

    Default

    with the line:
    AddOutputFilterByType DEFLATE text/html text/css text/xml text/plain text/javascript application/x-javascript application/xml application/xhtml+xml application/postscript
    You are only compressing things that are worth compressing. Video, pictures, audio, etc is not worth compressing because it is already compressed. Compressing even a 1mb html page (output by php) takes as much time as if it didn't do it at all. I have been running mine for months and WestHost has not talked to me at all about using too much CPU.
    For Dynamic pages such as php or things like that, there is no way to "pre-compress" the output because it is all dynamic.
    Unofficial technical support for the world.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •