Sohaib's Tech Blog

Something for every one

Displaying Files like phpinfo.php Nginx — 2017

Displaying Files like phpinfo.php Nginx

Problem I was having was is basically I cannot run a simple info.php inside my public_html after doing some research I came up with this rewrite if you’ve any other solution do let me know it works for me.

Nginx

This is to display all files inside your /home/domain/public_html

location / {

location ~ ^/(.+.php)$ {
try_files $uri =404;
root $MAGE_ROOT;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
try_files $uri $uri/ /index.php?$args;
}

 

Advertisements
Magento Page Cache Warming — 2017

Magento Page Cache Warming

Lets use a simple software to warm pages so they load faster and already in cache.

Before we do anything we need to install the following software

sudo apt-get install libxml-xpath-perl siege -y

Now lets setup Sitemap in Magento prior doing anything  – assuming that’s all taken care follow the following steps.

cat /home/yoursite/public_html/sitemap.xml | xpath -q -e "/urlset/url/loc/text()" > /root/tmp.urls

If the file is not local simply run the following

curl --silent http://example.com/sitemap.xml | xpath -q -e "/urlset/url/loc/text()" > tmp.urls

Now let’s make it warm

siege -v -c 1 -r `cat tmp.urls | wc -l` -f /root/tmp.urls

That’s it.

Magento 2 – (2.13) Failed to load resource: the server responded with a status of 404 (Not Found) **Solved —

Magento 2 – (2.13) Failed to load resource: the server responded with a status of 404 (Not Found) **Solved

After spending sometime with Magento 2 (2.13) , as I am running Nginx and PHP 7 fpm I was getting a lot of error and after some research I was able to find a solution simply replace location static in given magento 2 nginx configuration file and restart nginx and php fpm server to reflect changes.

location /static/ {
    if ($MAGE_MODE = "production") {
      expires max;
    }

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
      rewrite ^/static/(versiond*/)?(.*)$ /static/$2 last;
    }

    location ~* .(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
      add_header Cache-Control "public";
      add_header X-Frame-Options "SAMEORIGIN";
      expires +1y;

      if (!-f $request_filename) {
        rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
      }
    }

    location ~* .(zip|gz|gzip|bz2|csv|xml)$ {
      add_header Cache-Control "no-store";
      add_header X-Frame-Options "SAMEORIGIN";
      expires off;

      if (!-f $request_filename) {
         rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
      }
    }

    if (!-f $request_filename) {
      rewrite ^/static/(versiond*/)?(.*)$ /static.php?resource=$2 last;
    }

    add_header X-Frame-Options "SAMEORIGIN";
  }

 

How to install Nginx Google Page Speed on Ubuntu 16.10 x64 Xenial — 2017

How to install Nginx Google Page Speed on Ubuntu 16.10 x64 Xenial

Happy New Year !!!!!!

I am not going to bore you guys, I’ve already completed the building process and the hard work so you can enjoy .

Install Nginx with Google Page speed

At the time of building this we’ve latest stable version of

nginx version: nginx/1.10.2
built by gcc 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled

You need to install nginx deb package by simply running the following command

nginx_1.10.2-1-xenial_amd64.deb

Download Nginx Google Pagespeed

How to install Nginx Page Speed on Debian x64 Jessie —

How to install Nginx Page Speed on Debian x64 Jessie

Happy New Year !!!!!!

I am not going to bore you guys, I’ve already completed the building process and the hard work so you can enjoy .

Install Nginx with Google Page speed

At the time of building this we’ve latest stable version of

nginx version: nginx/1.10.2

built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1t 3 May 2016
TLS SNI support enabled

You need to install nginx deb package by simply running the following command

dpkg -i nginx_1.10.2-1-jessie_amd64.deb

Download Nginx Google Pagespeed

Google Pagespeed latest version as of Jan-4-2017

Nginx Deny From IP — 2015

Nginx Deny From IP

Nginx is a very unique Web Server, today I will show how to deny IP using Nginx, Please note you must have this module installed in your Nginx web server , If you don’t have it installed – Simply download my pre-compile Nginx which comes with all the necessary modules known to NGINX.

ngx_http_access_module

Will create a file under our conf directory lets called that block.conf, My conf directory is located at /etc/nginx/conf.d/.

We are going to assume YOUR IP Address i.e. 8.8.8.8 & 8.8.4.4

nano /etc/nginx/conf.d/block.conf

deny 9.9.9.9;
deny 8.8.8.8;
deny 8.8.4.4;

Once done restart your Nginx server

service nginx restart OR
service nginx reload

Great source to obtain fresh IP addresses is from Ip2location

You pick and choose any country from the above link and wont allow them access to your server.

How I got my Gtmetrix.com Score to 1.98s — 2015

How I got my Gtmetrix.com Score to 1.98s

My last project was very challenging where I was told to optimize Magento Site, Customer was using a dedicated server where I’ve to optimize not only Magento but also Optimize & Speed up the server, Took me some real time and hard work. I am happy Yayyyyy.

I don’t want to get in details as far as server configuration but I achieve 1.98s load time

Magento which was loading in 22s to 15s , I got it down to 1.98s

I’ve setup the following

APC
Memcached
Nginx with Pagespeed

If you need any assistance from me speeding up your Magento, Drop me a line, I charge flat $1,000 and trust me it takes a lot of time and effort, Oh yea client was using Amazon Cloudfront CDN but then he switch to Akamai CDN which is the TOP Dawg in CDN world I am here to assist.

So do you want to speed up your magento store ?

WebServer with Percona Google Pagespeed — 2014

WebServer with Percona Google Pagespeed

Today : I would like to share how you setup a fast Webs Server with MYSQL .

In this tutorial you don’t really need any control panel and waste your money, like Cpanel or this and that, I am not discouraging any one but I cant stand them.

We are setting up the following
NGINX
Google Page Speed
Percona *MYSQL Database
Memcahed
PHPmyadmin

No Apache so NO MORE .htaccess file…

In my environment, I have a 15GB Server with 200GB SSD RAID 10

Oh yea, before I forget I have a Ubuntu 12.04 Precise.

Assuming you are a ROOT user.

apt-get update
apt-get install memcached php5-cli php5-fpm php5-mysql php5-curl php5-gd php5-imagick php5-mcrypt php5-memcached php5-imap

Simply and easy and you are done.

Now let’s create a user and public_html

adduser sohaib

Go to

cd /home/sohaib/

Create public_html or whatever you wanted to call your HOME directory, regarding setting up nginx configuration How to Nginx Google Pagespeed

How to Install & Setup your NGINX Webserver —
How to Install Nginx with Google Page Speed — 2014

How to Install Nginx with Google Page Speed

Hello

Its been a long time since I last updated my blog as I was busy with so many other projects, Today I am going to show an easy way to install Nginx with Google Page speed.

I have only tested this with Ubuntu 12.04 Precise, So here it is

apt-get install python-software-properties
apt-get install software-properties-common
**OUTDATED** apt-add-repository ppa:sandyd/nginx-current-pagespeed
apt-add-repository ppa:adegtyarev/nginx-pagespeed
apt-get update
apt-get install nginx

You now have Nginx with Google Page Speed.

Test page speed by simply adding the following line

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Below is my Nginx configuration


server {
#port to listen on
listen 80;

# server name
server_name http://www.sohaib.com;

# root location
root /var/www/sohaib/public_html;

# access log
access_log /var/log/nginx/sohaib.com.access.log main;

# PageSpeed
pagespeed on;

# let’s speed up PageSpeed by storing it in the super duper fast memcached
pagespeed MemcachedThreads 1;
pagespeed MemcachedServers “localhost:11211”;

# show half the users an optimized site, half the regular site
pagespeed RunExperiment on;
pagespeed AnalyticsID UA-XXXXXXXXXX-1;
pagespeed ExperimentVariable 1;
pagespeed ExperimentSpec “id=1;percent=50;level=CoreFilters;enabled=collapse_whitespace,remove_comments;”;
pagespeed ExperimentSpec “id=2;percent=50”;

# Filter settings
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters collapse_whitespace,remove_comments;

# needs to exist and be writable by nginx
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# This is a temporary workaround that ensures requests for pagespeed
# optimized resources go to the pagespeed handler.
location ~ “.pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+” { }
location ~ “^/ngx_pagespeed_static/” { }
location ~ “^/ngx_pagespeed_beacon$” { }

}

Few More Tips for Page Speed which might help optimize your site

# disable CoreFilters
pagespeed RewriteLevel PassThrough;

# enable collapse whitespace filter
pagespeed EnableFilters collapse_whitespace;

# enable JavaScript library offload
pagespeed EnableFilters canonicalize_javascript_libraries;

# combine multiple CSS files into one
pagespeed EnableFilters combine_css;

# combine multiple JavaScript files into one
pagespeed EnableFilters combine_javascript;

# remove tags with default attributes
pagespeed EnableFilters elide_attributes;

# improve resource cacheability
pagespeed EnableFilters extend_cache;

# flatten CSS files by replacing @import with the imported file
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;

# defer the loading of images which are not visible to the client
pagespeed EnableFilters lazyload_images;

# enable JavaScript minification
pagespeed EnableFilters rewrite_javascript;

# enable image optimization
pagespeed EnableFilters rewrite_images;

# pre-solve DNS lookup
pagespeed EnableFilters insert_dns_prefetch;

# rewrite CSS to load page-rendering CSS rules first.
pagespeed EnableFilters prioritize_critical_css;
}

# enable CoreFilters
pagespeed RewriteLevel CoreFilters;

# disable particular filter(s) in CoreFilters
pagespeed DisableFilters rewrite_images;

# enable additional filter(s) selectively
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
}