How to enable Compression in Nginx

If you are using Nginx webserver, you have to try this out. I started exploring for this option when I faced slowness in rending the pages in one of the applications. When I checked the backend services, the web service API was given the responses quickly, but the page was taking more time to load. On further inspection, I figured out that the API was sending a a data of size 5 MB. So the browser will first download this data and this speed depends on the bandwidth.

I explored further and figured out the way of compressing API body using the webserver. This will speed up the API calls as the data transferred over the network will be very less. In my case, the 5 MB data became few KBs (size of compressed data). This will get extracted quickly in the browser and it gets rendered in the screen.

The required configurations are pasted below for quick reference.

Make the changes in the config file /etc/nginx/nginx.conf. Add the following content to the nginx.conf file.

gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";

 

The explanation of each of the parameters are given below.

  • gzip on; – enables gzip compression in nginx
  • gzip_vary on: – tells proxies to cache both compressed and normal versions of a resource
  • gzip_types – The type of files that can be compressed
  • gzip_disable “MSIE [1-6]\.”;  – Disable compression for Internet Explorer versions 1-6
  • gzip_min_length 1024; – Nginx will compress the files greater than this size and it will not compress anything less than this size.
  • gzip_proxied – compress data even for clients that are connecting via proxies

 

This is one of the way to improve the performance of APIs. The developers can focus on enhancing their logic and the admin or DevOps engineer can focus on enhancing the web server with optimal configuration. There are so many tricks and magics we can do in the web server. I will try to post some of those in my blog.

Hope this helps. 🙂 . Please comment if you face any issues.

Can’t open config file: /usr/local/ssl/openssl.cnf on Windows

I faced the above issue while trying to use openssl in window. I have downloaded openssl and extracted in my windows server. After that I tried executing the following command.

openssl.exe genrsa -out subdomain.mydomain.com.key 2048

Solution:

Open Powershell

set OPENSSL_CONF=c:\[PATH TO YOUR OPENSSL DIRECTORY]\bin\openssl.cnf

Now execute the openssl command to generate the certificate. It will work without any issues. I hope this is helpful.

How to check the performance of DNS in your network ?

I was checking for tools to benchmark the performance of DNS servers in my network. The reason behind this performance test was to identify the root cause of the internet slowness within my network. One of the good free tool that I found online is DNS Benchmark Tool.

This is a very light weight and portable tool. This is just 180KB and helps us to perform the DNS speeed test. With this tool I figured out one anonymous DNS server running in an individuals laptop also.

dns_server

I found this tool as a useful utility.

How to auto connect OpenVPN during windows boot up?

Generally we establish VPN connection using OpenVPN using the connect option present in GUI application. Sometimes we may came across situations in which we need to enable vpn auto connect on the system boot.

I got a similar requirement. I have a desktop server which is located remotely and I want to access it from my laptop. The desktop will be accessible only through my vpn. So if someone turns off the desktop, during reboot, the vpn needs to be autoconnected so that I can access it from my network without any assistance from others. Here is the steps that I followed to achieve this. I created a task in the windows task scheduler. My operating system was Windows 10 (The same steps will work in all the recent versions of windows)

Step 1: Open Task Scheduler

Search for Task Scheduler and Open the Task Scheduler

openvpn_OpenTaskScheduler

 

Step 2: Click on Create Task

Once you open the Task Scheduler, you can see several options. Select Create Task option to create a new task.

openvpn_createtask

Step 3: Configure the Task details

Start create the task by filling the following details in the General section.

openvpn_taskdetails

Step 4: Add new Trigger to the Task

Trigger is basically the parameter that tells the system when to trigger this action. We need to create a new Trigger for this task. Click on New and create a trigger as explained in the next step.

openvpn_createtrigger

Step 5: Configure the Trigger

We will configure the trigger details in this section. Choose Begin the task: At Start up. This means the task will be triggered during the startup of the system. Further tweaking can be made by setting the parameters in the advanced settings section.

openvpn_trigger

Step 6: Create new Action

This is the main section. This is the action that gets triggered by the task. Here we need to select action as “Start a program”. 

openvpn_create_action

Step 7: Configure Action

Our program is the openvpn client. Browse to the openvpn client installation and select the openvpn-gui.exe. The main part is the arguments section. We need to specify the config file in which we need to connect. Here my config file name is amal.ovpn and it is located in the config directory of openvpn installation. If we miss this argument, the openvpn auto connect will not work. To test this command, the simple thing that we can do is by directly executing the command in the command line (Powershell is recommended).

Eg: Go to the bin directory of OpenVPN (C:\Program Files\OpenVPN\bin) and open powershell there.

Execute the following command. The “amal.ovpn” can be replaced with your vpn config file name.

openvpn_powershell_testing If the above command is working fine, complete the action configuration and save the details.

openvpn_action_info

Note: The amal.ovpn is the vpn configuration file and is located in the OpenVPN config directory which defaults to “C:\Program Files\OpenVPN\config”

After configuring this, click on ok and save the task. Then test this task by rebooting the system. I have configured this set up several times in several places and it worked perfectly.

Hope this article helped you 🙂 . If you are facing any issues, please comment on this post, I will be happy to help you.

 

 

How to clear/delete the cached Kerberos ticket ?

In Linux

kdestroy

 

In Windows

klist purge

How to check the Java architecture from command line ?

To check the Java architecture whether it is 32 bit or 64 bit, the following commands will be helpful.

Execute the following commands in the command line and check the results

java -d32 -version

java -d64 -version

If any of the above command is giving an error message similar to “Error: This Java instance does not support a xx-bit JVM.” If it is not supporting 32 bit, then we can say it is a 64 bit Java. If it is not supporting 64 bit, we can say it is a 32-bit Java. The screenshot of the same is attached below.

java_screen.PNG

Hope this will help .. 🙂

Programmatic way to reboot EC2 instances

Sometimes we might have to reboot EC2 instances. If the requirement is to restart EC2 instances regularly, we can achieve it by writing a small piece of code. I also came across a similar requirement and a portion of the code I used is given below.

 

How to Press Cntrl+Alt+Del in Remote Desktop

This is very simple. But most of us doesn’t know this.

Just press  Cntrl+Alt+End, this will do Cntl+Alt+Del in the remotely taken desktop

Normal Cntrl+Alt+Del will work in the host machine.