NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
21.9k stars 2.53k forks source link

Add Google Pagespeed module? #1184

Open zeroone82 opened 3 years ago

zeroone82 commented 3 years ago

Is your feature request related to a problem? Please describe. Not an actual problem, but it could increase performance and scores for sites using NPM

Describe the solution you'd like Add pagespeed module to nginx.

Describe alternatives you've considered None

Additional context I found this script for integrating with openresty but wasn't able to test it: https://gist.github.com/marklkelly/d17fa535a41e0e3aa429

I tried manually loading it on a debian server before realizing it was using an old nginx version that doesn't support external modules (it has to be compiled with them), so I'm not sure how much a performance increase this module really offers.

It could be an additional switch for each host, so it's not enabled by default

zeroone82 commented 3 years ago

Just in case anyone wants to enable it too, I managed to get it working. I can't say for sure this is 100% the correct way to do it, but it works.

First I made a custom Dockerfile:

FROM jc21/nginx-proxy-manager:2.9.4

RUN apt update && apt install -y uuid-dev libssl-dev zlib1g-dev libpcre3 libpcre3-dev

#Download openresty & pagespeed
RUN cd /tmp && curl "https://openresty.org/download/openresty-1.19.3.1.tar.gz" | tar zx
RUN cd /tmp/openresty-1.19.3.1 && curl -O https://codeload.github.com/apache/incubator-pagespeed-ngx/zip/v1.14.33.1-RC1 && unzip v1.14.33.1-RC1 && rm v1.14.33.1-RC1
RUN cd /tmp/openresty-1.19.3.1/incubator-pagespeed-ngx-1.14.33.1-RC1 && curl https://dist.apache.org/repos/dist/release/incubator/pagespeed/1.14.36.1/x64/psol-1.14.36.1-apache-incubating-x64.tar.gz |tar zx

#Config and make
RUN cd /tmp/openresty-1.19.3.1 && \
    ./configure \
        --prefix=/etc/nginx \
        --sbin-path=/usr/sbin/nginx \
        --modules-path=/usr/lib/nginx/modules \
        --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --pid-path=/var/run/nginx.pid \
        --lock-path=/var/run/nginx.lock \
        --http-client-body-temp-path=/var/cache/nginx/client_temp \
        --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
        --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
        --user=nginx \
        --group=nginx \
        --with-compat \
        --with-threads \
        --with-http_addition_module \
        --with-http_auth_request_module \
        --with-http_dav_module \
        --with-http_flv_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-http_mp4_module \
        --with-http_random_index_module \
        --with-http_realip_module \
        --with-http_secure_link_module \
        --with-http_slice_module \
        --with-http_ssl_module \
        --with-http_stub_status_module \
        --with-http_sub_module \
        --with-http_v2_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-stream \
        --with-stream_realip_module \
        --with-stream_ssl_module \
        --with-stream_ssl_preread_module \
        --add-module=incubator-pagespeed-ngx-1.14.33.1-RC1 && \
    make -j2 && \
    make install

This should already result in an NGINX with Pagespeed module enable. Then to enable it for your site: Create the file data/nginx/custom/pagespeed.conf and a basic config:

pagespeed on;

pagespeed FileCachePath /var/lib/nginx/cache/pagespeed/;
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 50000;
pagespeed EnableCachePurge on;
pagespeed PurgeMethod PURGE;

# https://www.modpagespeed.com/doc/config_filters
pagespeed RewriteLevel CoreFilters;

Then on anyhost that you want to enable, add the config file in your custom configuration:

#Pagespeed config
include /data/nginx/custom/pagespeed.conf
binhotvn commented 1 year ago

I had updated a little bit base on @zeroone82 Dockerfile

FROM jc21/nginx-proxy-manager:latest

RUN apt update && apt install -y uuid-dev libssl-dev zlib1g-dev libpcre3 libpcre3-dev build-essential

#Download openresty & pagespeed
RUN cd /tmp && curl "https://openresty.org/download/openresty-1.21.4.1.tar.gz" | tar zx
RUN cd /tmp/openresty-1.21.4.1 && curl -O https://codeload.github.com/apache/incubator-pagespeed-ngx/zip/v1.14.33.1-RC1 && unzip v1.14.33.1-RC1 && rm v1.14.33.1-RC1
RUN cd /tmp/openresty-1.21.4.1/incubator-pagespeed-ngx-1.14.33.1-RC1 && curl https://dist.apache.org/repos/dist/release/incubator/pagespeed/1.14.36.1/x64/psol-1.14.36.1-apache-incubating-x64.tar.gz |tar zx

#Config and make
RUN cd /tmp/openresty-1.21.4.1 && \
    ./configure \
        --prefix=/etc/nginx \
        --sbin-path=/usr/sbin/nginx \
        --modules-path=/usr/lib/nginx/modules \
        --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --pid-path=/var/run/nginx.pid \
        --lock-path=/var/run/nginx.lock \
        --http-client-body-temp-path=/var/cache/nginx/client_temp \
        --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
        --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
        --user=nginx \
        --group=nginx \
        --with-compat \
        --with-threads \
        --with-http_addition_module \
        --with-http_auth_request_module \
        --with-http_dav_module \
        --with-http_flv_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-http_mp4_module \
        --with-http_random_index_module \
        --with-http_realip_module \
        --with-http_secure_link_module \
        --with-http_slice_module \
        --with-http_ssl_module \
        --with-http_stub_status_module \
        --with-http_sub_module \
        --with-http_v2_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-stream \
        --with-stream_realip_module \
        --with-stream_ssl_module \
        --with-stream_ssl_preread_module \
        --add-module=incubator-pagespeed-ngx-1.14.33.1-RC1 && \
    make -j2 && \
    make install

Dockerhub: https://hub.docker.com/r/binhotvn/nginx-proxy-manager-with-pagespeed

Passthrough config enable many features of ngx_pagespeed but use it with caution

# enable ngx_pagespeed
pagespeed on;

pagespeed FileCachePath /var/ngx_pagespeed_cache;

# let's speed up PageSpeed by storing it in the super duper fast memcached
# pagespeed MemcachedThreads 1;
# pagespeed MemcachedServers "localhost:11211";

# disable CoreFilters
pagespeed RewriteLevel PassThrough;

# enable collapse whitespace filter
pagespeed EnableFilters collapse_whitespace;

# enable JavaScript library offload
pagespeed EnableFilters canonicalize_javascript_libraries;

# combine multiple CSS files into one
pagespeed EnableFilters combine_css;

# combine multiple JavaScript files into one
pagespeed EnableFilters combine_javascript;

# remove tags with default attributes
pagespeed EnableFilters elide_attributes;

# improve resource cacheability
pagespeed EnableFilters extend_cache;

# flatten CSS files by replacing @import with the imported file
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;

# defer the loading of images which are not visible to the client
pagespeed EnableFilters lazyload_images;

# enable JavaScript minification
pagespeed EnableFilters rewrite_javascript;

# enable image optimization
pagespeed EnableFilters rewrite_images;

# pre-solve DNS lookup
pagespeed EnableFilters insert_dns_prefetch;

# rewrite CSS to load page-rendering CSS rules first.
pagespeed EnableFilters prioritize_critical_css;
viriatusX commented 1 year ago

Just in case anyone wants to enable it too, I managed to get it working. I can't say for sure this is 100% the correct way to do it, but it works.

First I made a custom Dockerfile:

FROM jc21/nginx-proxy-manager:2.9.4

RUN apt update && apt install -y uuid-dev libssl-dev zlib1g-dev libpcre3 libpcre3-dev

#Download openresty & pagespeed
RUN cd /tmp && curl "https://openresty.org/download/openresty-1.19.3.1.tar.gz" | tar zx
RUN cd /tmp/openresty-1.19.3.1 && curl -O https://codeload.github.com/apache/incubator-pagespeed-ngx/zip/v1.14.33.1-RC1 && unzip v1.14.33.1-RC1 && rm v1.14.33.1-RC1
RUN cd /tmp/openresty-1.19.3.1/incubator-pagespeed-ngx-1.14.33.1-RC1 && curl https://dist.apache.org/repos/dist/release/incubator/pagespeed/1.14.36.1/x64/psol-1.14.36.1-apache-incubating-x64.tar.gz |tar zx

#Config and make
RUN cd /tmp/openresty-1.19.3.1 && \
    ./configure \
        --prefix=/etc/nginx \
        --sbin-path=/usr/sbin/nginx \
        --modules-path=/usr/lib/nginx/modules \
        --conf-path=/etc/nginx/nginx.conf \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --pid-path=/var/run/nginx.pid \
        --lock-path=/var/run/nginx.lock \
        --http-client-body-temp-path=/var/cache/nginx/client_temp \
        --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
        --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
        --user=nginx \
        --group=nginx \
        --with-compat \
        --with-threads \
        --with-http_addition_module \
        --with-http_auth_request_module \
        --with-http_dav_module \
        --with-http_flv_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-http_mp4_module \
        --with-http_random_index_module \
        --with-http_realip_module \
        --with-http_secure_link_module \
        --with-http_slice_module \
        --with-http_ssl_module \
        --with-http_stub_status_module \
        --with-http_sub_module \
        --with-http_v2_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-stream \
        --with-stream_realip_module \
        --with-stream_ssl_module \
        --with-stream_ssl_preread_module \
        --add-module=incubator-pagespeed-ngx-1.14.33.1-RC1 && \
    make -j2 && \
    make install

This should already result in an NGINX with Pagespeed module enable. Then to enable it for your site: Create the file data/nginx/custom/pagespeed.conf and a basic config:

pagespeed on;

pagespeed FileCachePath /var/lib/nginx/cache/pagespeed/;
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 50000;
pagespeed EnableCachePurge on;
pagespeed PurgeMethod PURGE;

# https://www.modpagespeed.com/doc/config_filters
pagespeed RewriteLevel CoreFilters;

Then on anyhost that you want to enable, add the config file in your custom configuration:

#Pagespeed config
include /data/nginx/custom/pagespeed.conf

Hi! if I include "include /data/nginx/custom/pagespeed.conf" inside NPM on domain's Advanced tab, it's turn Offline...

binhotvn commented 1 year ago

domain's

It went offline because of missing of pagespeed.conf file, instead of doing that try my config above

viriatusX commented 1 year ago

domain's

It went offline because missing of pagespeed.conf file, instead of doing that try my config above

Thanks @binhotvn I am not familiar with DockerFile. I follow this tutorial to integrate SpeedPages + GEO2IP https://topete.gitbook.io/contenido/v/anadir-modulo-pagespeed-a-nginx-proxy-manager/ but since version 2.9.21 it doesn't work. The developer JC21 modified the S6 Overlay (I don't know if permissions) and it doesn't work anymore. It shows this error: s6-overlay-suexec: fatal: can only run as pid 1

Would you know to shed some light?

github-actions[bot] commented 2 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1: