Skip to content

Instantly share code, notes, and snippets.

@javdl
Last active June 22, 2016 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javdl/9d1c23c130f1e15176610390fbdf1064 to your computer and use it in GitHub Desktop.
Save javdl/9d1c23c130f1e15176610390fbdf1064 to your computer and use it in GitHub Desktop.

NGINX with Pagespeed and Upstream Proxy Cache with OpenResty misc module

https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
cd ~
NPS_VERSION=1.11.33.2
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip -O release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz  # extracts to psol
cd ~
OPENRESTY_MISC_VERSION=0.30
wget https://github.com/openresty/set-misc-nginx-module/archive/v${OPENRESTY_MISC_VERSION}.zip
unzip v${OPENRESTY_MISC_VERSION}.zip
cd ~
NGX_DEVEL_VERSION=0.3.0
wget https://github.com/simpl/ngx_devel_kit/archive/v${NGX_DEVEL_VERSION}.zip
unzip v${NGX_DEVEL_VERSION}.zip
cd ~
# check http://nginx.org/en/download.html for the latest version
NGINX_VERSION=1.10.1
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure --with-http_gzip_static_module        \
--with-http_stub_status_module        \
--with-pcre                           \
--with-file-aio                       \
--with-http_realip_module             \
--without-http_scgi_module            \
--without-http_uwsgi_module           \
--without-http_fastcgi_module \
--with-http_sub_module \
--add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta ${PS_NGX_EXTRA_FLAGS} \
--add-module=$HOME/ngx_devel_kit-${NGX_DEVEL_VERSION} \
--add-module=$HOME/set-misc-nginx-module-${OPENRESTY_MISC_VERSION}

make -j2
make install

ONLY FOR DOCKER, cleanup
Rm -rf nginx-${NGINX_VERSION}
Rm -rf ngx_pagespeed-release-${NPS_VERSION}-beta/

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"

Systemd file: https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ systemctl enable nginx.service

REMOVED:

--with-http_ssl_module \

https://www.digitalocean.com/community/tutorials/how-to-add-ngx_pagespeed-to-nginx-on-ubuntu-14-04

https://www.digitalocean.com/community/tutorials/how-to-compile-nginx-from-source-on-a-centos-6-4-x64-vps

--with-http_gzip_static_module option enables nginx to use gzip (Before serving a file from disk to a gzip-enabled client, this module will look for a precompressed file in the same location that ends in ".gz". The purpose is to avoid compressing the same file each time it is requested.).[recommended for reducing size of information sent]

--with-http_stub_status_module option enables other plugins over nginx to allow us to get the status (This module provides the ability to get some status from nginx.). [recommended for getting stats]

--with-http_ssl_module - required if you want to run a HTTPS server. See How To Create a SSL Certificate on nginx for CentOS 6

--with-pcre option enables to match routes via Regular Expression Matching when defining routes. [recommended, you will find more use of this once you start adding and matching routes]

--with-file-aio - enables asynchronous I/O, better than the default send file option(recommended if you are allowing users to download static files)

--with-http_realip_module is used for getting the IP of the client when behind a load balancer. This is useful when serving content behind CloudFlare like services.

--without-http_scgi_module - Disable SCGI module (normally used when running CGI scripts)

--without-http_uwsgi_module - Disable UWSGI module (normally used when running CGI scripts)

--without-http_fastcgi_module - Disable FastCGI module (normally used when running CGI scripts)

Init script for Upstart (Ubuntu 14.04), place in etc/init.d

https://www.nginx.com/resources/wiki/start/topics/examples/ubuntuupstart/

# nginx

description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"

start on (filesystem and net-device-up IFACE=lo)
stop on runlevel [!2345]

env DAEMON=/usr/local/nginx/sbin/nginx
env PID=/usr/local/nginx/logs/nginx.pid

expect fork
respawn
respawn limit 10 5
#oom never

pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        fi
end script

exec $DAEMON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment