Forked from gottaloveit/rebuld_nginx_with_pagespeed.sh
Created
November 22, 2013 13:41
-
-
Save dlsniper/7599996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "This script will rebuild a Debian style package (deb) of latest stable" | |
echo "Nginx. The original deb is from nginx.org apt repository." | |
echo | |
echo "This will prompt you yes or no on a few changes to the build as well as" | |
echo "it will compile and package the latest Google NGX Pagespeed module." | |
echo | |
echo "This is built and tested on Ubuntu 12.04 LTS, fresh OS install." | |
echo "There are no guarantees, and I take no liability if it breaks, but it" | |
echo "worked perfect on my machine." | |
echo | |
echo "Would you like to continue?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) break;; | |
No ) exit;; | |
esac | |
done | |
CHANGE_USER=no | |
REMOVE_DAV=no | |
REMOVE_FLV=no | |
REMOVE_MP4=no | |
REMOVE_MAIL=no | |
ADD_GEOIP=no | |
PATCH_SYSLOG=no | |
echo "Would you like to change the user and group to www-data instead of default (nginx)?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) CHANGE_USER=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to remove the http dav module?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) REMOVE_DAV=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to remove the http flv module?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) REMOVE_FLV=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to remove the http mp4 module?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) REMOVE_MP4=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to remove the mail and mail ssl modules?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) REMOVE_MAIL=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to add http-geoip module?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) ADD_GEOIP=yes; break;; | |
No ) break;; | |
esac | |
done | |
echo "Would you like to enable logging to syslog?" | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) PATCH_SYSLOG=yes; break;; | |
No ) break;; | |
esac | |
done | |
apt-get update && apt-get upgrade -y | |
apt-get install build-essential -y | |
apt-get build-dep nginx -y | |
apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev git unzip -y | |
wget http://nginx.org/keys/nginx_signing.key | |
apt-key add nginx_signing.key | |
echo "deb http://nginx.org/packages/debian/ squeeze nginx" > /etc/apt/sources.list.d/nginx.list | |
echo "deb-src http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list.d/nginx.list | |
apt-get update | |
cd /tmp | |
apt-get source nginx | |
NGINX_VER=$(find ./nginx* -maxdepth 0 -type d | sed "s|^\./||") | |
NGINX_BUILD_DIR=/tmp/$NGINX_VER | |
if [ "$CHANGE_USER" = "yes" ]; then | |
sed -ie s/--user=nginx/--user=www-data/g $NGINX_BUILD_DIR/debian/rules | |
sed -ie s/--group=nginx/--group=www-data/g $NGINX_BUILD_DIR/debian/rules | |
fi | |
if [ "$REMOVE_DAV" = "yes" ]; then | |
sed -i '/--with-http_dav_module \\/d' $NGINX_BUILD_DIR/debian/rules | |
fi | |
if [ "$REMOVE_FLV" = "yes" ]; then | |
sed -i '/--with-http_flv_module \\/d' $NGINX_BUILD_DIR/debian/rules | |
fi | |
if [ "$REMOVE_MP4" = "yes" ]; then | |
sed -i '/--with-http_mp4_module \\/d' $NGINX_BUILD_DIR/debian/rules | |
fi | |
if [ "$REMOVE_MAIL" = "yes" ]; then | |
sed -i '/--with-mail \\/d' $NGINX_BUILD_DIR/debian/rules | |
sed -i '/--with-mail_ssl_module \\/d' $NGINX_BUILD_DIR/debian/rules | |
fi | |
if [ "$ADD_GEOIP" = "yes" ]; then | |
sed -i '/--with-http_sub_module \\/i--with-http_geoip_module \\' $NGINX_BUILD_DIR/debian/rules | |
fi | |
mkdir $NGINX_BUILD_DIR/modules | |
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.6.29.5-beta.zip -O $NGINX_BUILD_DIR/modules/release-1.6.29.5-beta.zip | |
unzip $NGINX_BUILD_DIR/modules/release-1.6.29.5-beta.zip -d $NGINX_BUILD_DIR/modules | |
rm -f $NGINX_BUILD_DIR/modules/release-1.6.29.5-beta.zip | |
wget https://dl.google.com/dl/page-speed/psol/1.6.29.5.tar.gz -O $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-1.6.29.5-beta/1.6.29.5.tar.gz | |
tar -C $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-1.6.29.5-beta -xzf $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-1.6.29.5-beta/1.6.29.5.tar.gz | |
rm -f $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-1.6.29.5-beta/1.6.29.5.tar.gz | |
sed -i '/--with-file-aio \\/i--add-module=modules/ngx_pagespeed-release-1.6.29.5-beta \\' $NGINX_BUILD_DIR/debian/rules | |
if [ "$PATCH_SYSLOG" = "yes" ]; then | |
git clone https://github.com/yaoweibin/nginx_syslog_patch $NGINX_BUILD_DIR/modules/nginx_syslog_patch | |
patch -d $NGINX_BUILD_DIR -p1 < modules/nginx_syslog_patch/syslog_1.4.0.patch | |
sed -i '/--with-file-aio \\/i--add-module=modules/nginx_syslog_patch \\' $NGINX_BUILD_DIR/debian/rules | |
fi | |
cd $NGINX_BUILD_DIR | |
dpkg-buildpackage -b | |
echo | |
echo | |
echo | |
echo "***************************************************************" | |
echo "* install package from /tmp like so: *" | |
echo "* dpkg -i /tmp/nginx_1.4.2-1~squeeze_amd64.deb *" | |
echo "* or if you want the debug version *" | |
echo "* dpkg -i /tmp/nginx-debug_1.4.2-1~squeeze_amd64.deb *" | |
echo "* *" | |
if [ "$CHANGE_USER" = "yes" ]; then | |
echo "* REMEMBER TO CHANGE /etc/nginx/nginx.conf user to www-data *" | |
echo "* *" | |
fi | |
echo "* To test pagespeed: *" | |
echo "* in the file /etc/nginx/nginx.conf *" | |
echo "* add the following in the http { ... } block *" | |
echo "* pagespeed on; *" | |
echo "* pagespeed FileCachePath /var/ngx_pagespeed_cache; *" | |
echo "* *" | |
echo "* then: *" | |
echo "* mkdir /var/ngx_pagespeed_cache *" | |
if [ "$CHANGE_USER" = "yes" ]; then | |
echo "* chown www-data:www-data /var/ngx_pagespeed_cache *" | |
else | |
echo "* chown nginx:nginx /var/ngx_pagespeed_cache *" | |
fi | |
echo "* then: *" | |
echo "* /etc/init.d/nginx reload *" | |
echo "* curl -I -p http://localhost|grep X-Page-Speed *" | |
echo "* *" | |
if [ "$PATCH_SYSLOG" = "yes" ]; then | |
echo "* for logging to syslog: *" | |
echo "* see https://github.com/yaoweibin/nginx_syslog_patch *" | |
fi | |
echo "* *" | |
echo "***************************************************************" | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment