问题描述
我们正在尝试将 pagespeed 模块与 Nginx 网络服务器集成以压缩图像。 我们已经安装了 pagespeed 版本 1.13.35.2-0 和 Nginx 版本:Nginx/1.19.5
用于安装过程的参考文档: https://www.linuxbabe.com/nginx/compile-the-latest-nginx-with-ngx_pagespeed-module-on-ubuntu
我们已经观察到,x-pagespeed 标头仅出现在 html 页面中,而不出现在通过的图像和 css 页面中。图像不会被压缩或优化。
虚拟主机文件位置/etc/Nginx/sites-available/domainname.com.conf:
server {
listen 80;
server_name domainname.com;
access_log /var/log/Nginx/domainname-access.log;
error_log /var/log/Nginx/domainname-error.log;
set $bucket "storage.googleapis.com/bucket_name";
root /var/www/data;
# enable pagespeed module on this server block
pagespeed on;
pagespeed Statisticslogging on;
pagespeed LogDir /var/log/pagespeed;
pagespeed AdminPath /pagespeed_admin;
#pagespeed PreserveUrlRelativity on;
#pagespeed Domain storage.googleapis.com/bucket_name;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters defer_javascript;
pagespeed EnableFilters sprite_images;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters recompress_png;
pagespeed EnableFilters convert_png_to_jpeg,convert_jpeg_to_webp;
pagespeed EnableFilters collapse_whitespace,remove_comments;
location ~ ^/pagespeed_admin {
allow 0.0.0.0;
#deny all;
}
location ~ ^/ngx_pagespeed_beacon/(?<name>.*) {
resolver 8.8.8.8;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Authorization '';
#proxy_set_header Host $bucket;
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_hide_header x-amz-Meta-server-side-encryption;
proxy_hide_header x-amz-server-side-encryption;
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;
proxy_intercept_errors on;
#add_header Cache-Control max-age=31536000;
add_header X-Decoded-Message $name;
proxy_pass https://$bucket/$name;
}
# location / {
# root /var/www/data/;
#deny all;
# }
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
pagespeed RewriteLevel CoreFilters;
}
请在下面找到/etc/Nginx/Nginx.conf:
user www-data;
worker_processes auto;
pid /run/Nginx.pid;
include /etc/Nginx/modules-enabled/*.conf;
load_module modules/ngx_pagespeed.so;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/Nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3,ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/Nginx/access.log;
error_log /var/log/Nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+RSS text/javascript;
##
# Virtual Host Configs
##
include /etc/Nginx/conf.d/*.conf;
include /etc/Nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.Nginx.org/ImapAuthenticateWithApachePHPScript
#
# # auth_http localhost/auth.PHP;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIdplUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
**在 Nginx 中安装或启用的模块是:
$ Nginx -V**
Nginx 版本:Nginx/1.19.5 使用 OpenSSL 1.1.1g 构建,2020 年 4 月 21 日(使用 OpenSSL 1.1.1i 运行,2020 年 12 月 8 日) 启用 TLS SNI 支持 配置参数:--with-cc-opt='-g -O2 -fdebug-prefix-map=/build/Nginx-90Ez86/Nginx-1.19.5=。 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,Now -fPIC' --prefix=/usr/share/Nginx --conf-path=/etc/Nginx/Nginx.conf --http-log-path=/var/log/Nginx/access.log --error-log-path=/var/log/Nginx/error.log --lock-path=/var/lock/Nginx.lock --pid-path=/run/Nginx.pid --modules-path= /usr/lib/Nginx/modules --http-client-body-temp-path=/var/lib/Nginx/body --http-fastcgi-temp-path=/var/lib/Nginx/fastcgi --http- proxy-temp-path=/var/lib/Nginx/proxy --http-scgi-temp-path=/var/lib/Nginx/scgi --http-uwsgi-temp-path=/var/lib/Nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with -http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module
$ Nginx -V 2>&1 | tr -- - '\n' | grep 模块
模块 路径=/usr/lib/Nginx/modules http_ssl_module http_stub_status_module http_realip_module http_auth_request_module http_v2_module http_dav_module http_slice_module http_addition_module http_gunzip_module http_gzip_static_module http_sub_module
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)