Nginx – How to set expires headers for images

Nginx - How to set expires headers for images

nginx (engine x)

In Nginx, you can easily set browser caching for your images. Nginx sets the ‘Expires’ and ‘Cache-Control’ http request headers for images nginx serves. This allows the client’s browser to cache the images for the amount of time specified by the expires tag inside the location block of code.

Here’s the location block I’m using in my Nginx virtual host configuration file:


location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 1y;
log_not_found off;
}

You can use the curl command on unix/linux/mac to see the full headers for a request. Here is an example of the full headers nginx is setting for an image after using expires headers.


# curl -I http://nicholaskuechler.com/wp-content/uploads/2011/02/cropped-andromeda-galaxy11.jpg
HTTP/1.1 200 OK
Server: nginx/1.0.0
Date: Sun, 24 Apr 2011 04:26:46 GMT
Content-Type: image/jpeg
Content-Length: 66713
Last-Modified: Fri, 25 Feb 2011 08:34:30 GMT
Connection: keep-alive
Expires: Mon, 23 Apr 2012 04:26:46 GMT
Cache-Control: max-age=31536000
Accept-Ranges: bytes

I noticed after putting the nginx expires in place and utilizing client browser caching, my Google Page Speed score increased by 5 points. Excellent!

Posted in nginx | Tagged , , , , | 2 Comments

Favorite Quotes: Winston Churchill on Optimism and Pessimism

Winston Churchill on Optimism and Pessimism

Winston Churchill on Optimism and Pessimism

“A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty.” – Winston Churchill

Portrait of Winston Churchill by Yousuf Karsh

Posted in Favorite Quotes | Tagged , , , | 3 Comments

Perl: How to list all installed perl modules

Perl: How to list all installed perl modules I was looking for an easy way to clone my perl modules from one server to another but I wasn’t sure how to easily list my installed perl modules. I searched around and found the instmodsh command which lists all currently installed perl modules.

I found Instmodsh is easy to use. In your terminal type ‘insmodsh’ to use it and this will bring you to an interactive shell tool.

Here is an example listing installed perl modules with the ‘instmodsh’ command:


devbox:~# instmodsh
Available commands are:
l - List all installed modules
m - Select a module
q - Quit the program
cmd?

To list all perl modules type ‘l’ in the instmodsh shell:


cmd? l
Installed modules are:
AI::Categorizer
AI::DecisionTree
Algorithm::NaiveBayes
Cache::Cache
Class::Accessor
Class::Data::Inheritable
Devel::StackTrace
Exception::Class
HTML::Mason
IO::Tty
Lingua::StopWords
Log::Any
MealMaster
Net::AMQP
Net::Stomp
POE
POE::Component::Client::AMQP
POE::Test::Loops
Perl
Statistics::Contingency
Test::Deep
Test::NoWarnings
Test::Simple
Test::Tester
Time::Progress
XML::RSS::Parser::Lite
YAML::LibYAML
cmd?

As you can see instmodsh is an easy way to list all of your install perl modules.

Posted in Perl | Tagged , , , , , | Leave a comment

Favorite Quotes: Buddhist and Zen Proverbs on Why Worrying is Pointless

Buddhist monks and Zen practitioners have a proverb or saying on why there is no use in worrying. Worrying about something is pointless.

The Buddhist proverb on worrying:

“If you have a problem that can be fixed, then there is no use in worrying. If you have a problem that cannot be fixed, then there is no use in worrying.” – Buddhist proverb

The Zen saying on worrying:

“If the problem has a solution, worrying is pointless, in the end the problem will be solved. If the problem has no solution, there is no reason to worry, because it can’t be solved.” – Zen saying

Posted in Favorite Quotes | Leave a comment

Debian & Ubuntu Equivalents of ‘yum whatprovides’

Introduction

For Debian and Ubuntu users there are three easy ways to find what package a file on your system is from. Those Red Hat, Fedora, or CentOS over to a Debian or Ubuntu system may have become used to using ‘yum whatprovides’. There is no whatprovides equivalent in aptitude or apt-get. But there are three easy to use debian/ubuntu alternatives to ‘yum whatprovides’: the Ubuntu packages search web site, the apt-file package, and the ‘dpkg -S’ command.

Ubuntu Packages Search

The first method is simple: Ubuntu provides a web site where you can search the package repositories and pull up detailed information on the packages. Visit the Ubuntu Packages Search site. Scroll down to the section titled "Search the contents of packages", which will search file manifests and all other package information. Enter in the path of the file you are looking for, such as "/etc/ssl/certs/ca-certificates.crt" or "ca-certificates.crt". and hit search. Very easy to use.

apt-file

The apt-file tool can also substitute for ‘yum whatprovides’. The apt-file package must first be installed using aptitude or apt-get. Simply run an ‘aptitude install apt-file’ to install it.

After you install the apt-file package, you must run ‘apt-file update’ to update it’s files database. Remember to run ‘apt-file’ update if you haven’t used it in a while, to make sure your apt-file database is up to date.

Now to determine the package a file is from, use the ‘apt-file search’ command. Here’s an example which shows the base packages my apache2 web server is currently using:

# apt-file search /usr/sbin/apache2
apache2-dbg: /usr/lib/debug/usr/sbin/apache2-mpm-event
apache2-dbg: /usr/lib/debug/usr/sbin/apache2-mpm-prefork
apache2-dbg: /usr/lib/debug/usr/sbin/apache2-mpm-worker
apache2-mpm-event: /usr/sbin/apache2
apache2-mpm-itk: /usr/sbin/apache2
apache2-mpm-prefork: /usr/sbin/apache2
apache2-mpm-worker: /usr/sbin/apache2
apache2.2-common: /usr/sbin/apache2ctl

dpkg -S

Another way to find the package name is using ‘dpkg -S’. This command will quickly tell you the package name it originated from. However it will only work for packages already install on your system. You can also use ‘dpkg -S’ without providing a full path for a very broad search.

Let’s find out what package the python binary /usr/bin/python is from:

# dpkg -S /usr/bin/python
python-minimal: /usr/bin/python

Let’s find out what package /usr/bin/python-config is from:

# dpkg -S /usr/bin/python-config
python-dev: /usr/bin/python-config
Posted in Linux | Tagged , , , , , , , , | Leave a comment