Nginx Requests Not Being Gzipped on CDN Pass-Through

A couple months ago I ran into a curious situation. Requests from Nginx were being gzipped as expected and requests from CDN were being gzipped. My Nginx settings for compression looked like this:


gzip on;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 0;
gzip_types application/json application/x-javascript application/javascript text/plain text/css text/javascript text/xml;
gzip_vary on;
gzip_disable "MSIE [1-6]\."; 

Reproducing the behavior was simple enough. If you hit the URI at CDN and append a cache busting string to the end of the URI such as \?2342343243 the headers would return without the Content-Encoding: gzip header. Another test to confirm this was to use a curl statement passing the via header with any value such as below

 

curl -v -H “Accept-Encoding: gzip” -H “Via: 1.1 akamai.net(ghost) (AkamaiGHost)”  "http://youruri.com” 

A simple explanation of this issue is that when request hits the CDN and the object is not cached, the request is then passed to origin using the via header. Unless the Nginx gzip directive of gzip_proxied any; is included this request will always be sent uncompressed. To resolve add this line to your nginx.conf file. Below is the same example shown earlier but including this directive:


gzip  on;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 0;
gzip_types application/json application/x-javascript application/javascript text/plain text/css text/javascript text/xml;
gzip_proxied any;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";

Enabling and Disabling Trim for 3rd Party SSDs in OSX

A few years ago I purchased a 2012 Mac mini that came with the super slow 5400 RPM 1TB disk. The cost of purchasing the system with an SSD was what I considered to be outrageous so I opted to install a 3rd party SSD (Samsung EVO drive) with great success using Carbon Copy Cloner. What I soon realizes is that OSX does not support trim for 3rd party SSDs by default.

What is Trim? Trim is the process by which the OS performs garbage collection of space that is no longer in use on the SSD to keep space available and the drive performant. There is a way within OSX to enable trim for 3rd party SSDs, however before enabling it be advised that it will enable it for all drives attached and taking a backup or using time machine would be a reasonable step just in case something goes sideways. Also worth noting is that enabling or disabling trim will require a reboot.

To enable trim on 3rd party SSDs in 10.11 and newer run the following command in terminal:

sudo trimforce enable

If you no longer want to have trim enabled you can simply run this command to disable it:

sudo trimforce disable

Adding Puppet Forge Modules as Git Submodules

Locate Module on the Forge

Locate the module in question on the forge. The next step is to identify any other unmet dependancies for the forge module and make note of them as well. For example the Chocolatey forge module requires windows_env and powershell as dependancies. Typically googling for the module author, module name, and the word Puppet will turn up the appropriate github result.

 

Add The Submodule

Adding the submodule is done via the CLI on your local instance.

git submodule add <path to clone from git> <path within Puppet repo>

Generally speaking the path within the Puppet will be modules/<module name>

 

The below example is for Chocolatey:

git submodule add git@github.com:chocolatey/puppet-chocolatey.git modules/chocolatey

 

 

Init and Update The Submodule

Once you have added the git submodule you will need to initialize and update it using the following commands:

Initialize Submodule
git submodule init
Submodule Update
git submodule update

 

Commit to Origin

The next step in the process is to commit the changes to our Github instance. Depending on the preferred workflow of the team this can either be done as a Pull Request or committed straight into prod.

Your git status should show changes to the .gitmodules directory.

 

Pulling to Puppet Master

Pull production to the production environment. This will not initialize or update the module, this will simply update the git module. The steps below will initialize and update the submodule within the production master.

Initialize Submodule
git submodule init
Submodule Update
git submodule update <modulename>