编译安装 Nginx 1.20.2,并增加 Sticky 和 nginx_upstream_check_module 模块

nginx_upstream_check_module 模块的作用主要是为 Nginx 的 upstream(上游服务器) 提供主动健康检查 和一些负载均衡增强功能。

1、具体来说,它的功能和作用如下:
主动健康检查(Active Health Check)
默认 Nginx 的 upstream 只能被动发现后端宕机(通过连接失败或响应超时)。
安装了 nginx_upstream_check_module 后,可以:
定期向后端服务器发送 HTTP 请求或 TCP 探针。
判断后端服务器是否可用。
动将不可用的服务器标记为 down,从负载均衡池中剔除。

2、支持多种类型:
type=http → 用于 HTTP 服务。
type=https → 用于 HTTPS 服务。
type=tcp → 用于 TCP 服务(非 HTTP)。

interval:检查间隔,例如 `interval=5000` 表示每 5 秒检查一次。
rise:连续成功多少次后,判定节点恢复正常。
fall:连续失败多少次后,判定节点不可用。
timeout:检查请求超时时间(毫秒)。

3、可自定义 HTTP 请求报文。
判断响应状态码是否正常,例如 2xx 或 3xx。

4、设置可用更新源

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
wget -4 --no-check-certificate -O /etc/yum.repos.d/CentOS-Base.repo https://www.zhangfangzhou.cn/third/Centos-7.repo

5、下载源码

### Nginx 源码
wget https://nginx.org/download/nginx-1.20.2.tar.gz
tar -zxvf nginx-1.20.2.tar.gz

### zlib(可选,用于数据压缩)
wget http://www.zlib.net/zlib-1.2.13.tar.gz
tar -zxf zlib-1.2.13.tar.gz

### PCRE(支持正则表达式匹配)
wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.45.tar.gz
tar -zxf pcre-8.45.tar.gz

### OpenSSL(支持 HTTPS)
wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz
tar -zxf openssl-1.1.1t.tar.gz
mv openssl-1.1.1t openssl

### Sticky 模块
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/08a395c66e42.zip -O sticky.zip
unzip sticky.zip
mv nginx-goodies-nginx-sticky* nginx-sticky

### nginx_upstream_check_module
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip -O nginx_upstream_check_module-master.zip
unzip nginx_upstream_check_module-master.zip

6、编译安装

yum -y install libtool  
#zlib 是提供数据压缩之用的库 (非必要编译安装)
cd ~
cd zlib-1.2.13
./configure --prefix=/usr/local/zlib
make && make install
echo "/usr/local/zlib/lib" > /etc/ld.so.conf.d/zlib.conf
ldconfig

#pcre PCRE库是一组函数,它们使用与Perl 5相同的语法和语义实现正则表达式模式匹配.(非必要编译安装)
cd ~
sudo yum install gcc-c++ -y
tar -zxf pcre-8.45.tar.gz
cd pcre-8.45
./configure --prefix=/usr/local/pcre --enable-utf8
make && make install
~/pcre-8.45/libtool --finish  /usr/local/pcre/lib/
echo "/usr/local/pcre/lib/" > /etc/ld.so.conf.d/pcre.conf
ldconfig

## 安装 Patch 工具(为 nginx_upstream_check_module 打补丁)
yum install -y patch

ngstable=1.20.2
#Install Nginx
cd ~
yum -y install gzip man
tar -zxf nginx-${ngstable}.tar.gz
#
#Custom nginx name
sed -i 's@^#define NGINX_VER          "nginx/" NGINX_VERSION@#define NGINX_VER          "Microsoft-IIS/10.0/" NGINX_VERSION@g'  ~/nginx-${ngstable}/src/core/nginx.h
sed -i 's@^#define NGINX_VAR          "NGINX"@#define NGINX_VAR          "Microsoft-IIS"@g'  ~/nginx-${ngstable}/src/core/nginx.h
sed -i '30,40s@nginx@Microsoft-IIS@g'  ~/nginx-${ngstable}/src/http/ngx_http_special_response.c
sed -i '45,50s@nginx@Microsoft-IIS@g' ~/nginx-${ngstable}/src/http/ngx_http_header_filter_module.c
#
#Nginx shows the file name length of a static directory file
sed -i 's/^#define NGX_HTTP_AUTOINDEX_PREALLOCATE  50/#define NGX_HTTP_AUTOINDEX_PREALLOCATE  150/'  ~/nginx-${ngstable}/src/http/modules/ngx_http_autoindex_module.c
sed -i 's/^#define NGX_HTTP_AUTOINDEX_NAME_LEN     50/#define NGX_HTTP_AUTOINDEX_NAME_LEN     150/'  ~/nginx-${ngstable}/src/http/modules/ngx_http_autoindex_module.c
#
yum install -y patch
cd ~/nginx-${ngstable}
patch -p1 < ../nginx_upstream_check_module-master/check_1.20.1+.patch
# patch -p1 < ../nginx_upstream_check_module-master/check_1.20.1+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h

#Copy NGINX manual page to /usr/share/man/man8:
cp -f ~/nginx-${ngstable}/man/nginx.8 /usr/share/man/man8
gzip /usr/share/man/man8/nginx.8

cd ~/nginx-${ngstable}
./configure --prefix=/usr/local/nginx --user=www --group=www \
--build=CentOS \
--modules-path=/usr/local/nginx/modules \
--with-openssl=/root/openssl \
--with-pcre=/root/pcre-8.45 \
--with-zlib=/root/zlib-1.2.13 \
--add-module=/root/nginx-sticky \
--add-module=/root/nginx_upstream_check_module-master \
--with-http_stub_status_module \
--with-http_secure_link_module \
--with-threads \
--with-file-aio \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_sub_module \
--with-http_dav_module \
--with-stream \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module
make -j$(nproc)
make install

7、平滑升级nginx

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

#然后拷贝一份新编译的二进制文件:
cp ~/nginx-${ngstable}/objs/nginx /usr/local/nginx/sbin/

#检测配置
nginx -t
kill -USR2 `cat /var/run/nginx.pid`
kill -HUP `cat /var/run/nginx.pid`

8、修改配置

upstream oah {
sticky; # 会话保持
server 10.53.121.51:8080;
server 10.53.121.52:8080;
server 10.53.121.53:8080;
server 10.53.121.66:8080;
server 10.53.121.67:8080;
# TCP 健康检查,只检测端口是否可用
check interval=5000 rise=2 fall=3 timeout=3000 type=tcp;
}

9、添加status页面
location /status {
check_status;
}

nginx.service start-pre operation timed out. Terminating.

问题
服务器重启后Nginx服务不会自动启动,手动启动Nginx服务没有出现任何问题。

错误状态
#systemctl status nginx
nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: timeout) since Fri 2020-02-28 19:13:13 CST; 6min ago
Docs: http://nginx.org/en/docs/
Process: 806 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=killed, signal=TERM)

Feb 28 19:11:43 izj6cdtn3gxvjysis55g0hz systemd[1]: Starting nginx - high performance web server...
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: nginx.service start-pre operation timed out. Terminating.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: Failed to start nginx - high performance web server.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: Unit nginx.service entered failed state.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: nginx.service failed.

#journalctl -u nginx.service
-- Logs begin at Sat 2020-02-29 03:11:38 CST, end at Fri 2020-02-28 19:20:01 CST. --
Feb 28 19:11:43 izj6cdtn3gxvjysis55g0hz systemd[1]: Starting nginx - high performance web server...
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: nginx.service start-pre operation timed out. Terminating.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: Failed to start nginx - high performance web server.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: Unit nginx.service entered failed state.
Feb 28 19:13:13 izj6cdtn3gxvjysis55g0hz systemd[1]: nginx.service failed.

原因
没有足够的超时值来启动Nginx服务

解决办法
vim /usr/lib/systemd/system/nginx.service
增加TimeoutStartSec参数值:
[Service]
...
TimeoutStartSec=600
-------------------------------------------
例子
cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
LimitNOFILE=51200
LimitNPROC=51200
LimitCORE=51200
TimeoutStartSec=600

[Install]
WantedBy=multi-user.target
--------------------------------------------

这个情况也可能出现在其他服务上面,没有足够的超时值来启动Nginx或Apache或者其他服务

CentOS7
使用任何文本编辑器(例如vi)打开初始化init脚本:
对于Apache: /usr/lib/systemd/system/httpd.service
对于nginx: /usr/lib/systemd/system/nginx.service

增加TimeoutStartSec参数值
[Service]
...
TimeoutStartSec=600

Debian9或者Ubuntu18
可以使用以下命令找到确切初始化脚本
systemctl status apache2.service | grep loaded
systemctl status nginx.service | grep loaded

使用任何文本编辑器(例如vi)打开初始化init脚本:
对于Apache:/lib/systemd/system/apache2.service
对于nginx:/lib/systemd/system/nginx.service

增加TimeoutStartSec参数值
[Service]
...
TimeoutStartSec=600
https://support.plesk.com/hc/en-us/articles/213387149-Nginx-Apache-are-not-running-after-server-reboot-on-a-Plesk-server-service-start-operation-timed-out-Terminating

Baidu Sitemap Generator 报错,WordPress发现了您的插件造成的错误:Baidu Sitemap Generator

升级PHP7.3之后,发现WordPress的Baidu Sitemap Generator在生成百度 XMLSitemap 生成器插件出现如下错误
错误详情
============
错误类别E_ERROR发生在文件www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/sitemap-function.php的439行。错误信息:Uncaught Error: Call to undefined function split() in www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/sitemap-function.php:439
Stack trace:
#0 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(278): xml_annotate()
#1 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(264): build_baidu_sitemap_xml('https...', 1)
#2 www.zhangfangzhou.cn/wp-content/plugins/baidu-sitemap-generator/baidu_sitemap.php(110): build_baidu_sitemap(1)
......
......
因为这款插件一直没有更新,PHP7版本废弃了一些PHP函数,split这个函数在PHP7版本已经不支持了,因此必须替换成PHP7版本的preg_split函数。

修复Baidu Sitemap Generator 报错需要修改2个地方

1、修改Baidu Sitemap Generator插件目录下的sitemap-function.php文件的439行和baidu_sitemap.php文件的308行
修改成

list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', $blogtime );

就是用preg_split替换掉split

2、修改Baidu Sitemap Generator插件目录下的baidu_sitemap.php


function baidu_sitemap_menu() {
/** Add a page to the options section of the website **/
if (current_user_can('manage_options'))
add_options_page("Baidu-Sitemap","Baidu-Sitemap", 8, __FILE__, 'baidu_sitemap_optionpage')
}
修改成
function baidu_sitemap_menu() {
/** Add a page to the options section of the website **/
if (current_user_can('manage_options'))
add_options_page("Baidu-Sitemap","Baidu-Sitemap", 'manage_options', __FILE__, 'baidu_sitemap_optionpage');
}

就是把8换成'manage_options'
修改完成后重启PHP,即可更新百度 XMLSitemap

利用.user.ini设置open_basedir加强php系统安全性

利用.user.ini设置open_basedir加强php系统安全性,从而限制PHP脚本动作只发生在指定目录里面,从而一定程度加强系统安全性。

1、.user.ini配置
要使.user.ini生效,需要修改php.ini 中的这两个参数#http://php.net/manual/zh/configuration.file.per-user.php
user_ini.filename = ".user.ini" #取消前面的;
user_ini.cache_ttl = 300 #取消前面的;

在网站项目根目录/data/html/www.zhangfangzhou.cn/创建 .user.ini文件,写入如下内容
vi .user.ini
open_basedir=/data/html/www.zhangfangzhou.cn/:/tmp/:/proc/

open_basedir中用冒号分割,分割成了3个路径。
open_basedir一定要以斜线结尾,如果没有用斜线结尾的话,则代表的是一系列以对应名称开头的目录。比如/user 代表的就是 /user(*)/ ,所以一定要注意斜线结尾。

2、设置权限防止被恶意删除导致open_basedir限制失效
chattr +i /data/html/www.zhangfangzhou.cn/.user.ini #通过chattr命令修改.user.ini的Immutable属性

chattr - 更改Linux文件系统上的文件属性
a Append Only,系统只允许在这个文件之后追加数据,不允许任何进程覆盖或截断这个文件。如果目录具有这个属性,系统将只允许在这个目录下建立和修改文件,而不允许删除任何文件。
i Immutable,系统不允许对这个文件进行任何的修改。如果目录具有这个属性,那么任何的进程只能修改目录之下的文件,不允许建立和删除文件。

3、取消.user.ini的Immutable属性(可以删除.user.ini)
chattr -i /data/html/www.zhangfangzhou.cn/.user.ini

Nginx编译加载使用动态模块(Dynamic Shared Object)(DSO)

Nginx编译加载使用动态模块(Dynamic Shared Object)(DSO)
Nginx版本必须>=1.9.11

查看支持的动态模块
[root@localhost nginx-1.12.2]# ./configure --help | grep dynamic
--with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module
--with-http_image_filter_module=dynamic
enable dynamic ngx_http_image_filter_module
--with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module
--with-http_perl_module=dynamic enable dynamic ngx_http_perl_module
--with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module
--with-stream=dynamic enable dynamic TCP/UDP proxy module
--with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module
--add-dynamic-module=PATH enable dynamic external module
--with-compat dynamic modules compatibility

编译时候的参数
--with-stream \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module

使用stream动态模块
user www www;
worker_processes auto;
worker_cpu_affinity auto;

load_module "modules/ngx_stream_module.so";

error_log /home/wwwlogs/error_nginx.log warn;#debug | info | notice | warn | error | crit ]
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events {
use epoll;
worker_connections 51200;
multi_accept on;
}

stream {
server {
listen 20020;
proxy_pass 192.168.122.214:3389;
}
server {
listen 20021;
proxy_pass 192.168.122.200:3389;
}
}
......
......

CentOS 6.x升级系统和PHP的curl,利用curl和cron自动重启https网站的php-fpm

CentOS 6.x升级系统和PHP的curl,利用curl和cron自动重启https网站的php-fpm
curl -I https://www.zhangfangzhou.cn/
curl: (35) SSL connect error #需要升级curl

wget https://curl.haxx.se/download/curl-7.50.0.tar.gz
tar -zxvf curl-7.50.0.tar.gz
cd curl-7.50.0
./configure --prefix=/usr/local/curl
make
make install
cp /usr/local/curl/bin/curl /usr/bin/curl #在源码的文件夹里面也有/root/curl-7.50.0/src/curl

curl --version
curl 7.50.0 (x86_64-pc-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2

php源码编译
--with-curl=/usr/local/curl/

502 Bad Gateway 自动重启脚本
#!/bin/bash
website="https://www.zhangfangzhou.cn/ https://www.zhangfangzhou.com"
if
/usr/bin/curl -I $website|grep "HTTP/1.1 502"
then
/bin/date -R >>/root/502.log
/etc/rc.d/init.d/nginx restart
fi

给予可执行权限:
chmod +x /root/502.sh

通过 crontab 设置周期运行:
crontab -u root -e
* * * * * /root/502.sh >/dev/null 2>&1

CentOS6 Nginx启用ngx_pagespeed加速站点访问

CentOS6 Nginx启用ngx_pagespeed加速站点访问
1、PageSpeed的功能特性

PageSpeed模块可以使用数量众多的重写"过滤器",每个过滤器都可以选择性地开启/关闭,从而自动进行各种优化(比如,减小文档大小、减少HTTP请求数据、减少HTTP往返次数以及缩短DNS解析时间)。

下面是ngx_pagespeed支持的其中一些过滤器。想了解支持的全部过滤器,请参阅官方文档。

Collapse Whitespace(压缩空白):通过把HTML网页中的多处连续空白换成一处空白,减少带宽使用量。
Canonicalize JavaScript Libraries(规范化转换JavaScript库):通过自动把流行的JavaScript库换成免费托管的JavaScript库(比如由谷歌托管),减少带宽使用量。
Combine CSS(合并CSS):通过把多个CSS文件合并成一个CSS文件,减少HTTP请求数量。
Combine JavaScript(合并JavaScript):通过把多个JavaScript文件合并成一个JavaScript文件,减少HTTP请求数量。
Elide Attributes(省略属性):通过删除由默认属性指定的标签,缩小文档大小。
Extend Cache(扩展缓存):通过优化网页资源的可缓存性,减少带宽使用量。
Flatten CSS Imports(精简CSS导入):通过删除CSS文件中的@import,减少HTTP请求往返次数。
Lazyload Images(延时加载图片):延时加载在客户端浏览器上看不见的图片。
Minify JavaScript(缩小JavaScript):通过缩小JavaScript,减少带宽使用量。
Optimize Images(优化图片):通过引入更多的内嵌图片、压缩图片,或者将GIF图片转换成PNG图片,优化图片分发。
Pre-Resolve DNS(预解析DNS):通过预解析DNS,缩短DNS解析时间。
Prioritize Critical CSS(优化加载关键CSS规则):重写CSS文件,以便首先加载渲染页面的CSS规则。

2、下载解压PageSpeed模块
Scientific Linux 6 provides gcc-4.8 packages that work on CentOS 6.
sudo rpm --import https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/devtoolset/slc6-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils

cd /usr/local/src/
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.11.33.3-beta.zip
unzip -q release-1.11.33.3-beta.zip
wget https://dl.google.com/dl/page-speed/psol/1.11.33.3.tar.gz
tar xzf 1.11.33.3.tar.gz -C ngx_pagespeed-release-1.11.33.3-beta #解压出来的psol文件夹到上面ngx_pagespeed-release-1.11.33.3-beta文件夹内

3、然后到nginx源码目录,添加以下代码重新编译nginx
./configure --prefix=/usr/local/nginx --user=www --group=www\
--add-module=/root/ngx_http_google_filter_module \
--add-module=/root/ngx_http_substitutions_filter_module \
--add-module=/root/ngx_pagespeed-release-1.11.33.3-beta \
--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc \
--with-openssl=/root/openssl \
--with-pcre=/root/pcre \
--with-zlib=/root/zlib \
--with-http_stub_status_module \
--with-http_secure_link_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_sub_module \
--with-stream \
--with-stream_ssl_module
make //不需要安装 make install
/etc/init.d/nginx stop
cd objs/
cp nginx /usr/local/nginx/sbin/ //覆盖原文件
/etc/init.d/nginx start

4、配置Nginx中的ngx_pagespeed模块
PageSpeed过滤器,有两种不同的级别可供你选择:CoreFilters和PassThrough。除非有所指定,否则默认情况下使用CoreFilters。
使用CoreFilters

server {
# 侦听的端口
listen 80;
# 服务器名称
server_name www.zhangfangzhou.cn;
# 记下根目录
root /usr/local/nginx/html;
# 访问日志
access_log /var/log/nginx/access.log main;
# 启用ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# 启用CoreFilters
pagespeed RewriteLevel CoreFilters;
# 禁用CoreFilters中的某些过滤器
pagespeed DisableFilters rewrite_images;
# 选择性地启用额外的过滤器
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
}

对高级用户而言:使用PassThrough

server {
# 侦听的端口
listen 80;
# 服务器名称
server_name www.zhangfangzhou.cn;
# 记下根目录
root /usr/local/nginx/html;
# 访问日志
access_log /var/log/nginx/access.log main;
# 启用ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# 禁用CoreFilters
pagespeed RewriteLevel PassThrough;
# 启用压缩空白过滤器
pagespeed EnableFilters collapse_whitespace;
# 启用JavaScript库卸载
pagespeed EnableFilters canonicalize_javascript_libraries;
# 把多个CSS文件合并成一个CSS文件
pagespeed EnableFilters combine_css;
# 把多个JavaScript文件合并成一个JavaScript文件
pagespeed EnableFilters combine_javascript;
# 删除带默认属性的标签
pagespeed EnableFilters elide_attributes;
# 改善资源的可缓存性
pagespeed EnableFilters extend_cache;
# 更换被导入文件的@import,精简CSS文件
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;
# 延时加载客户端看不见的图片
pagespeed EnableFilters lazyload_images;
# 启用JavaScript缩小机制
pagespeed EnableFilters rewrite_javascript;
# 启用图片优化机制
pagespeed EnableFilters rewrite_images;
# 预解析DNS查询
pagespeed EnableFilters insert_dns_prefetch;
# 重写CSS,首先加载渲染页面的CSS规则
pagespeed EnableFilters prioritize_critical_css;
}

5、建立缓存文件夹并赋予nginx用户权限

sudo mkdir /var/ngx_pagespeed_cache
sudo chown www:www /var/ngx_pagespeed_cache

修改Nginx源码,使header头信息伪装成其他页面服务器软件

nginx_header
Nginx 修改源码,header 头信息伪装成其他服务器软件

wget http://nginx.org/download/nginx-1.10.1.tar.gz
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

1、修改编译nginx核心文件

vim ./src/core/nginx.h

/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
*/

#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_

#define nginx_version 1006002 #这里最好不要乱改,某些扩展模块编译时,会检测版本,可能会出现错误,如lua_nginx_module
#define NGINX_VERSION "1.6.2" #这里随便改个版本号
#define NGINX_VER "squid/" NGINX_VERSION #这里改成我们想要的名字

#define NGINX_VAR "squid" #这里也一并修改
#define NGX_OLDPID_EXT ".oldbin"