Last active
August 29, 2015 14:19
-
-
Save yungke/16aca086996e826e9f69 to your computer and use it in GitHub Desktop.
Nginx 下安裝 PageSpeed module
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
sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make unzip |
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
cd | |
NPS_VERSION=1.9.32.3 | |
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.9.32.3-beta.zip | |
unzip release-1.9.32.3-beta.zip | |
cd ngx_pagespeed-release-1.9.32.3-beta/ | |
wget https://dl.google.com/dl/page-speed/psol/1.9.32.3.tar.gz | |
tar -xzvf 1.9.32.3.tar.gz |
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
cd | |
# check http://nginx.org/en/download.html for the latest version | |
NGINX_VERSION=1.6.2 | |
wget http://nginx.org/download/nginx-1.6.2.tar.gz | |
tar -xvzf nginx-1.6.2.tar.gz | |
cd nginx-1.6.2/ | |
./configure –add-module=$HOME/ngx_pagespeed-release-1.9.32.3-beta | |
make | |
sudo make install |
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
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-ipv6 –add-module=$HOME/ngx_pagespeed-release-1.9.32.3-beta |
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
mkdir /var/ngx_pagespeed_cache | |
chown www.www /var/ngx_pagespeed_cache | |
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf$(date +%m%d) # 備份 nginx 配置文件 |
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
/usr/local/nginx/conf/pagespeed_handler.conf |
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
# ngx_pagespeed config | |
pagespeed FileCachePath /var/ngx_pagespeed_cache; # Use tmpfs for best results. | |
pagespeed RewriteLevel CoreFilters; | |
pagespeed EnableFilters local_storage_cache; | |
pagespeed EnableFilters collapse_whitespace,remove_comments; | |
pagespeed EnableFilters outline_css; | |
pagespeed EnableFilters flatten_css_imports; | |
pagespeed EnableFilters move_css_above_scripts; | |
pagespeed EnableFilters move_css_to_head; | |
pagespeed EnableFilters outline_javascript; | |
pagespeed EnableFilters combine_javascript; | |
pagespeed EnableFilters combine_css; | |
pagespeed EnableFilters rewrite_javascript; | |
pagespeed EnableFilters rewrite_css,sprite_images; | |
pagespeed EnableFilters rewrite_style_attributes; | |
pagespeed EnableFilters recompress_images; | |
pagespeed EnableFilters resize_images; | |
pagespeed EnableFilters convert_meta_tags; | |
pagespeed EnableFilters inline_preview_images; | |
pagespeed EnableFilters resize_mobile_images; | |
pagespeed EnableFilters lazyload_images; | |
pagespeed LazyloadImagesAfterOnload off; | |
pagespeed LazyloadImagesBlankUrl “http://www.gstatic.com/psa/static/1.gif”; | |
# 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 ~ “^/ngx_pagespeed_static/” { } | |
location ~ “^/ngx_pagespeed_beacon$” { } | |
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; } | |
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; } | |
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; } | |
location /pagespeed_console { allow 127.0.0.1; deny all; } |
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
# vim /usr/local/nginx/conf/nginx.conf | |
server { | |
# [...] | |
pagespeed on; | |
include pagespeed_handler.conf; | |
# [...] | |
} |
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
# /usr/local/nginx/sbin/nginx -t | |
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok | |
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful | |
# curl -I 'http://freebaking.net' | grep X-Page-Speed | |
% Total % Received % Xferd Average Speed Time Time Time Current | |
Dload Upload Total Spent Left Speed | |
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0 | |
X-Page-Speed: 1.9.32.3-4448 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment