In my previous blog post, I mentioned that I switched to Nginx web service from Apache to speed things up a bit. For some unknown reasons, I couldn’t get Apache for handle traffic to this blog without crashing daily.

So I switched to Nginx web server and signed up for Google’s PageSpeed Service which is still in beta. Even though the service is still in beta, this site is enjoying some benefits already.

Google PageSpeed Service helps speed up customer websites by applying web performance best practices. It works by retrieving original web pages from the customer’s servers, then serving those pages on behalf of the customer after applying performance best practices.

This can result is faster loading time and good user experience for your sites.

If you’re planning on using PageSpeed Service and Nginx web server, here’s one setup you’ll have to configure to get the best result. Because PageSpeed fetches content from your servers and serves that content to users, all original requests to your original server will be from Google IP addresses and not your customers’.

If you want to track users based on locations or block spammers, you won’t be able to because your servers will only see Google’s IP addresses in its log file. To fix that when using Nginx, follow the steps below.

If Nginx is already working, open its main config file called nginx.conf. This file is mostly located in /etc/nginx directory.

When it opens, copy and paste the content below in the http {  }  block of the file and save it.

set_real_ip_from  216.239.32.0/19;
set_real_ip_from  64.233.160.0/19;
set_real_ip_from  66.249.80.0/20;
set_real_ip_from  72.14.192.0/18;
set_real_ip_from  209.85.128.0/17;
set_real_ip_from  66.102.0.0/20;
set_real_ip_from  74.125.0.0/16;
set_real_ip_from  64.18.0.0/20;
set_real_ip_from  207.126.144.0/20;
set_real_ip_from  173.194.0.0/16;
set_real_ip_from  2001:4860:4000::/36;
set_real_ip_from  2404:6800:4000::/36;
set_real_ip_from  2607:f8b0:4000::/36;
set_real_ip_from  2800:3f0:4000::/36;
set_real_ip_from  2a00:1450:4000::/36;
set_real_ip_from  2c0f:fb50:4000::/36;
real_ip_header    X-Forwarded-For;

 

This is a list of Google IP addresses and subnet that will used to route traffic to your site. You will server will record all