Methods to disable Nginx cache when user is authenticated in Drupal

There are some cases we only need Nginx cache enabled for anonymous users. I can show two ways on how to disable Nginx cache when user is authenticated and enable it for anonymous users in Drupal.

Method 1: Using Cookie

This method invloves Drupal custom module to set an identifier in Cookie that a user is authenticated.

The custom module uses hook_user_login() to set "nocache=1" in Cookie if user is logged in and hook_user_logout() to set "nocache=0" if user is logged out. The codes are as follows (you can download the custom module below this article):

How to setup Pagespeed module in Nginx using rpm or yum on CentOS 7

Adding Pagespeed module in Apache is very easy with package manager:

sudo yum install at # if you do not already have 'at' installed
sudo rpm -U mod-pagespeed-*.rpm

... but if we want to add Pagespeed module in Nginx, first thing we think of is compiling its source along with the Pagespeed module. What if Nginx is installed in our server from yum or rpm? The process we need is to repackage RPM and that is what this tutorial will show.

Solution to NGINX upstream servers HTTP keepalive enabled serving wrong URL and content

With HTTP keepalive enabled in NGINX upstream servers reduces latency thus improves performance and it reduces the possibility that the NGINX runs out of ephemeral ports. Following the suggestion given by NGINX doc that the proxy_http_version directive should be set to "1.1" and the "Connection" header field should be cleared:

Get Drush to run Drupal cron regularly using crontab

Drush can Drupal cron without the need of accessing<key>. This means we can safely remove or redirect cron.php to 404 Not Found in our .htaccess:

RewriteRule cron.php / [R=404,L]

To make our crontab script simple, we will use Drush's site aliases. Example if we are running multiple sites in our server:, and we can assign alias @site1, @site2 and @site3 respectively. To do this:


How to fix inaccessible flash drive identified by computer as "USB Disk 30X USB Device"

Having a bootable Linux on flash drive is very handly tool for a web developer. When I was about to create one, my TDK 16GB flash drive becomes inaccessible in my Windows 7 file explorer. The Windows explorer detected it and shows "Removable drive (H:)". When I clicked the drive, it prompted me to insert a disk in Drive H: as if it were acting as a CD or DVD drive. I checked it on my "Device Manager" and found my flash drive registered as "USB Disk 30X USB Device". I tried some known fix: uninstalled/re-installed the drive's device driver, re-assigned new Drive letter and nothing worked.

Setup Rock Mongo web interface

I was looking for a admin web interface for mongoDB just like PHPMyAdmin for My SQL and found RockMongo a good one. In this article will show how to setup RockMongo using the authentication created in your mongoDB service. Please checkout this article Setup Drupal 7 Panopoly distribution with mongoDB on CentOS 7 if you haven't setup your mongoDB service and its PHP driver in your server.

Using SASS breakpoint mixin

One of the SASS mixins that I used a lot is the breakpoint. It makes the media queries in SASS simple and elegant. But first get the mixin at We can now write our media queries in SASS in the following manner:

@import "stylesheets/breakpoint";
.menu {
  @include breakpoint($screen-xs) { 
    font-size: 1em;
  font-size: 1.4em;

The CSS output: