Monday, December 10, 2018

Find Request Execution Time of Each Request in Apache

Apache access log provides many useful parameters which are very helpful while debugging. Requester IP, request url, user agent, request response code, request response size, request creation time etc but if you want to know the execution time of each request, there is nothing wrong with this requirement.

To achieve this, you need to make modifications in LogFormat attribute of apache configuration file.

You can find this parameter in apache configuration file of RPM based distributions like CentOS as well as Debian based distributions like Ubuntu. 

You need to add %T or %D parameters in the LogFormat of apache configuration file. Search following line
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
and change into
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" **%T/%D**" combined
We have just added %T and %D in value of the attribute.  

%T shows the response time in Seconds and %D shows the response time in microseconds. %D is very useful for short time response or to find exact value of response.
Suppose any request takes 7 seconds to finish, you can find its microseconds value in access log something like 7458962 or 7896547.

You can find apache configuration file in /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf. Similarly you can find access log file in /var/log/apache2/access.log or /var/log/httpd/access_log  

Friday, November 23, 2018

Run the Django Oscar Sandbox Locally

git clone https://github.com/django-oscar/django-oscar.git

cd django-oscar

mkvirtualenv oscar  # needs virtualenvwrapper

make sandbox

The sandbox site (initialized with a sample set of products) will be available at: http://localhost:8000  

A sample superuser is installed with credentials:
username : superuser
email        : superuser@example.com
password : testing

Monday, November 19, 2018

nginx - Enable Leverage Browser Caching

If you are trying to enable Leverage Browser Caching for your site in nginx and it still shows not enabled in Google PageSpeed Insights and GTmetrix.

Solution :
1) Edit file /etc/nginx/sites-enabled/default
2) Add line
expires 365d;
in your virtualhost under "server {" above "location / {"
3) Restart nginx


Example :
server {
    listen 80;
    server_name yourdomainname.com;
    expires 365d;
    client_max_body_size 128M;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8080;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
        add_header X-Frame-Options SAMEORIGIN; 
        add_header X-Content-Type-Options nosniff; 
        add_header X-XSS-Protection "1; mode=block"; 
        proxy_hide_header X-Powered-By;
        server_tokens off;
        autoindex off;
        etag off;
    }

}