- 
      
 - 
        
Save cybersholt/6e0906cebacaeb897dcd05428533d40d to your computer and use it in GitHub Desktop.  
    How to Install Nginx and Google PageSpeed on Debian/Ubuntu
  
        
  
    
      This file contains hidden or 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 | |
| ## Install PageSpeed on Debian 8/9 and Ubuntu 16.04 64Bits | |
| ## https://www.howtoforge.com/tutorial/how-to-install-nginx-and-google-pagespeed-on-ubuntu-16-04/ | |
| ## http://nginx.org/en/linux_packages.html | |
| ## https://www.modpagespeed.com/doc/build_ngx_pagespeed_from_source | |
| ## https://developers.google.com/speed/pagespeed/module/ | |
| ## Debian ISO: https://cdimage.debian.org/cdimage/archive/8.9.0/amd64/iso-cd/ | |
| ## Run as root (sudo su) | |
| NPS_VERSION=1.12.34.3-stable | |
| NPS_RELEASE_NUMBER=${NPS_VERSION/stable/} | |
| apt-get update && apt-get install -y lsb-release | |
| OSRELEASE=$(lsb_release -si | awk '{print tolower($0)}') | |
| CODENAME=$(lsb_release -sc) | |
| echo "deb http://nginx.org/packages/$OSRELEASE/ $CODENAME nginx" > /etc/apt/sources.list.d/nginx.list | |
| echo "deb-src http://nginx.org/packages/$OSRELEASE/ $CODENAME nginx" >> /etc/apt/sources.list.d/nginx.list | |
| wget http://nginx.org/keys/nginx_signing.key | |
| apt-key add nginx_signing.key && rm -f nginx_signing.key && apt-get update | |
| apt-get install -y dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip | |
| cd ~ | |
| mkdir -p ~/nginx_source/ | |
| cd ~/nginx_source/ | |
| apt-get source nginx | |
| rm -rf /var/lib/apt/lists/ | |
| apt-get update | |
| apt-get build-dep -y nginx | |
| cd ~ | |
| wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}.tar.gz | |
| tar xvfz v${NPS_VERSION}.tar.gz | |
| cd ngx_pagespeed-${NPS_VERSION}/ | |
| psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz | |
| psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL) | |
| wget ${psol_url} | |
| tar -xzvf $(basename ${psol_url}) | |
| sed -i "s|--prefix=/etc/nginx|--prefix=/etc/nginx --add-module=$HOME/ngx_pagespeed-${NPS_VERSION}|" $HOME/nginx_source/nginx-1.1*.*/debian/rules | |
| cd ~/nginx_source/nginx-1.1*.*/ | |
| dpkg-buildpackage -b | |
| cd ../ | |
| dpkg -i *.deb | |
| ## Para Finalizar | |
| mkdir -p /var/ngx_pagespeed_cache | |
| chmod 777 /var/ngx_pagespeed_cache | |
| ## Set on PageSpeed Config /etc/nginx/conf.d/default.conf | |
| sed -i "s|# concurs with nginx's one|include /etc/nginx/mod_pagespeed.conf;|" /etc/nginx/conf.d/default.conf | |
| echo 'pagespeed on; | |
| pagespeed FileCachePath /var/ngx_pagespeed_cache; | |
| location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { | |
| add_header "" ""; | |
| } | |
| location ~ "^/pagespeed_static/" { } | |
| location ~ "^/ngx_pagespeed_beacon$" { }' >/etc/nginx/mod_pagespeed.conf | |
| ## Para checar as configs do Nginx | |
| nginx -t | |
| ## Reinciar o Nginx | |
| systemctl restart nginx | |
| ## Delete nginx list | |
| /etc/apt/sources.list.d/nginx.list | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment