本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/79852918
1,关于pagespeed
是一个 google的 pagespeed 优化页面Nginx 模块。
能够压缩html css js 图片,自动优化网页。
超级厉害呢。
项目地址:
https://www.modpagespeed.com
GitHub:
https://github.com/apache/incubator-pagespeed-ngx
已经放到apache 孵化器里面了。
2,构建dockerfile
docker已经非常的流行了。
给出dockerfile 别人就能一样构建出环境。
超级喜欢。
FROM debian:stretch-slim
RUN echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib" > /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian/ stretch-proposed-updates main non-free contrib" >> /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib" >> /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian/ stretch-proposed-updates main non-free contrib" >> /etc/apt/sources.list
USER root
ENV Nginx_VERSION 1.9.9
RUN apt-get update && apt-get install -y build-essential zlib1g-dev libssl-dev libpcre3 libpcre3-dev unzip uuid-dev curl && \
cd /root && curl -O http://Nginx.org/download/Nginx-1.9.9.tar.gz && \
curl -o latest-stable.tar.gz https://codeload.github.com/apache/incubator-pagespeed-ngx/tar.gz/latest-stable && \
tar -zxvf Nginx-1.9.9.tar.gz && tar -zxvf latest-stable.tar.gz && cd /root/incubator-pagespeed-ngx-latest-stable && \
curl -O https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz && tar -xzvf 1.13.35.2-x64.tar.gz
RUN cd /root/Nginx-1.9.9 && ./configure --add-module=/root/incubator-pagespeed-ngx-latest-stable --with-http_mp4_module \
--with-http_sub_module --with-http_stub_status_module --with-http_v2_module && \
make && make install && rm -rf /root/* && apt-get remove -y build-essential unzip ADD Nginx.conf /usr/local/Nginx/conf/Nginx.conf ENTRYPOINT ["/usr/local/Nginx/sbin/Nginx","-g","daemon off;"]
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/Nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
pagespeed on;
pagespeed AdminPath /pagespeed_admin;
pagespeed ConsolePath /pagespeed_console;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed GlobalAdminPath /pagespeed_global_admin;
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
# save on bandwidth and load resources directly from file system
resolver 8.8.8.8;
pagespeed UseNativeFetcher on;
pagespeed NoTransformOptimizedImages on;
pagespeed InPlaceResourceOptimization on;
pagespeed ProcessScriptVariables on;
pagespeed PreserveUrlRelativity on;
pagespeed EnableCachePurge on;
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed RateLimitBackgroundFetches off;
pagespeed RespectVary off;
pagespeed CriticalImagesBeaconEnabled true;
pagespeed FetchWithGzip on;
pagespeed InPlaceWaitForOptimized on;
pagespeed InPlaceRewriteDeadlineMs 100000;
pagespeed CacheFlushPollIntervalSec 0;
pagespeed HttpCacheCompressionLevel 9;
pagespeed XHeaderValue "powered by sun";
pagespeed LogDir "/var/log/pagespeed";
pagespeed FileCachePath "/var/cache/ngx_pagespeed";
pagespeed FileCacheSizeKb 102400000;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 5000000;
pagespeed LRUCacheKbPerProcess 32000;
pagespeed LRUCacheByteLimit 16384;
pagespeed DefaultSharedMemoryCacheKB 500000;
pagespeed MessageBufferSize 200000;
pagespeed StatisticsLoggingIntervalMs 60000;
pagespeed StatisticsLoggingMaxFileSizeKb 1024;
pagespeed MaxSegmentLength 500;
pagespeed MaxCombinedJsBytes 276480;
# optimization filters
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters extend_cache;
# code related optimization
pagespeed EnableFilters remove_comments;
pagespeed EnableFilters collapse_whitespace;
# DNS related optimization
pagespeed EnableFilters insert_dns_prefetch;
# additional settings
pagespeed FetchHttps enable,allow_self_signed;
pagespeed FetcherTimeoutMs 2000;
pagespeed ImageMaxRewritesAtOnce 1000;
pagespeed RewriteDeadlinePerFlushMs 2000;
pagespeed NumRewriteThreads 16;
pagespeed NumExpensiveRewriteThreads 64;
pagespeed ImplicitCacheTtlMs 1800000;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
access_log logs/host.access.log main;
error_log logs/host.error.log;
location ~ ^/pagespeed_admin {
allow all;
}
location / {
root html;
index index.html index.htm;
}
location = /status {
access_log off;
stub_status;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
编译好了,之后就可以启动了。
折腾半天,原来是配置不对,没有启动。
3,查看效果
启动之后就可以看效果了。把html 空格去掉了。自动优化呢。
同时使用pagespeed_admin 可以看到很多配置。直观很多。
4,总结
pagespeed 非常强大,使用非常简单。直接压缩优化了。
这个只是简单的跑通了,更多Nginx 参数可以参考:
https://github.com/27Bslash6/docker/blob/master/nginx-pagespeed/Dockerfile
本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/79852918