Nginx is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP proxy server, originally written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites including Yandex, Mail.Ru, VK, and Rambler. According to Netcraft, nginx served or proxied 22.61% busiest sites in August 2015. Here are some of the success stories: Netflix, Wordpress.com, FastMail.FM.
Ngxpagespeed speeds up your site and reduces page load time by automatically applying web performance best practices to pages and associated assets (CSS, JavaScript, images) without requiring you to modify your existing content or workflow. Features include:
• Image optimization: stripping meta-data, dynamic resizing, recompression
• CSS & JavaScript minification, concatenation, inlining, and outlining
• Small resource inlining
• Deferring image and JavaScript loading
• HTML rewriting
• Cache lifetime extension
• and more
- Ubuntu 12.04, 14.04, 16.04
- root privileges
- few knowledge using vim
sudo apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
sudo nano /etc/apt/sources.list.d/nginx.list
Paste in two string
For 12.04:
deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx
For 14.04:
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx
For 16.04:
deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx
After that update
sudo apt-get update
Command stop and show strings like that:
GPG error: http://nginx.org <name package> Release: The following signatures couldn't be verified because the public key is not available: NOPUBKEY ABF5BD8xxxxxxx
Don't worry add this key

wget -q "http://nginx.org/packages/keys/nginx_signing.key" -O-| sudo apt-key add -
repeat
sudo apt-get update
It’s simple like never before, just run.
bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version latest
They ask you start for every major step. And finish.
Step 1 you may skip, installer detect missing dependencies.
http://kbeezie.com/debian-ubuntu-nginx-init-script/
On this page default initial script for control NGINX
You may create that script yourself.
sudo nano /etc/init.d/nginx
Paste script and change path to installing package.
After Step 3 your package local in /usr/local/nginx/
Or paste that
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/nginx:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Now run this command to give your script executable permissions.
sudo chmod +x /etc/init.d/nginx
for start use:
sudo /etc/init.d/nginx start
for stop:
sudo /etc/init.d/nginx stop
for restart:
sudo /etc/init.d/nginx restart
for reload:
sudo /etc/init.d/nginx reload
Now our NGINX must run and need see that real, if you not blocking 80 port you can just enter to your server ip, or
curl -I -p http://localhost
Ok, NGINX start, but we need NGX-pagespeed.
PageSpeed Configuration
Enabling the Module
In Nginx the configuration typically should go in your nginx.conf which for source installs defaults to being in:
/usr/local/nginx/conf/
In Apache PageSpeed is enabled automatically when you install the module while in Nginx you need to add several lines to your nginx.conf. In every server block where PageSpeed is enabled add
Ok that we know what do next paste in every block nginx.conf code
sudo nano /usr/local/nginx/conf/nginx.conf
Paste this code:
pagespeed on;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
Save and restart reload nginx
sudo /etc/init.d/nginx reload
Now use curl
curl -I -p http://localhost
It’s ALL. No need scripts any more.
P.S. for configure like wanna you - go here :
https://developers.google.com/speed/pagespeed/module/configuration