server {listen80default_server;listen443ssl;server_name_;ssl_certificate/credential/default/default.crt;ssl_certificate_key/credential/default/default.key;return444; }
目前Wordpress缓存方案有很多,主流的静态页面缓存插件也是有很多,代表的WP Rocket、 WP super cache、W3 Total Cache等,也有用key-value缓存数据库的方案,代表的有Redis和Memcached缓存方案。前者静态页面插件采用PHP方式把页面缓存为静态文件,访问的时候通过Nginx-PHP-数据库-静态缓存页面,后者是通过Nginx-PHP-键值缓存数据库-生产页面。通过以上对比我们就会发现,都依然无法避免访问到后台的PHP和数据库或者键值缓存数据库。而我们理想最快的方式是通过Nginx直接访问静态页面,但是可惜除了整站生成静态没有其他办法,并且整站静态的文件更新是个大问题。因此很多人采用了Nginx FastCGI Cache缓存方案。让Nginx通过自带的FastCGI Cache直接缓存页面到内存,访问的时候可以最快的访问到我们请求的页面。
WordPress后台安装Nginx Helper 插件后,点击Setting设置,开启Enable Purge,启用nginx Fastcgi cache (requires external settings for nginx),你还可以再页面源码底部增加FastCache的缓存时间戳:开启Enable Nginx Timestamp in HTML;选择Delete local server cache files.
<!--Cached using Nginx-Helper on 2024-04-19 21:37:12. It took 347 queries executed in 0.811 seconds.-->
<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with Angie by using --with-openssl=<path> option.
译自Freenginx: A Fork of Nginx,作者 Steven J. Vaughan-Nichols 也称为 sjvn,自从 CP/M-80 成为尖端的 PC 操作系统,300bps 成为快速的互联网连接,WordStar 成为最先进的文字处理器以来,他就一直撰写有关技术和技术业务的文章,而我们也很享受这一切。
一名志愿的 Nginx 开发者正在把Nginx(发音为 EngineX,是世界上最流行的 Web 服务器分叉为 Freenginx。
根据Netcraft的统计,Nginx 是世界上最受欢迎的 Web 服务器。因此,当 Nginx 的顶级开发者 MaximDounin宣布他要分支 Nginx时,这可能是一个巨大的举动。
#按照编译依赖和工具yuminstallmercurialpsmiscnet-toolswgetcurlbuild-essentiallsb-releasecmakegolanglibunwind-devgitlibpcre3-devzlib1g-devhg#下载nginx-quic和boringssl源码hgclone-bquichttps://hg.nginx.org/nginx-quic--insecuregitclonehttps://boringssl.googlesource.com/boringssl#编译boringssl的密码库,以备nginx编译引用cdboringsslmkdir-pbuild.openssl/lib.openssl/include# 建立软链接,注意其中的路径根据你的下载路径的情况进行调整ln-sf/root/src/boringssl/include/openssl/root/src/boringssl/.openssl/include/openssl# 生成库文件touch/root/src/boringssl/.openssl/include/openssl/ssl.h# 预编译cmake-B/root/src/boringssl/build-H/root/src/boringssl# 编译 make-C/root/src/boringssl/build# 拷贝编译好的库文件cp/root/src/boringssl/build/crypto/libcrypto.a/root/src/boringssl/build/ssl/libssl.a/root/src/boringssl/.openssl/lib#增加nginx运行用户和用户组/usr/sbin/groupadd-fwww/usr/sbin/useradd-gwwwwwwcd..cdnginx-quic#取消 debug 模式进行编译设置sed-i's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@'auto/cc/gcc#configure#注意需要密码库的引用和nginx模块的启用;详见:http://hg.nginx.org/nginx-quic/file/tip/README./auto/configure\--prefix=/usr/local/nginx\--user=www\--group=www\--with-http_stub_status_module\--with-http_v2_module\--with-http_ssl_module\--with-http_gzip_static_module\--with-http_realip_module\--with-http_flv_module\--with-http_mp4_module\--with-pcre\--with-pcre-jit\--with-zlib=../zlib-cf\--add-module=../nginx-ct\--add-module=../ngx_brotli\--with-ld-opt='-ljemalloc'\--with-cc-opt="-I../boringssl/include"\--with-ld-opt="-L../boringssl/build/ssl \ -L../boringssl/build/crypto"\--with-debug--with-http_v3_module\--with-http_quic_module\--with-stream_quic_module#编译安装make && makeinstall#其他参照nginx编译后配置如下:vim/etc/profile#末尾增加以下内容PATH=$PATH:/usr/local/php/bin:/usr/local/nginx/sbinexportPATH#内容结尾source/etc/profile#增加系统服务vim/lib/systemd/system/nginx.service#输入以下内容[Unit]Description=nginx-highperformancewebserverDocumentation=http://nginx.org/en/docs/After=network.target[Service]Type=forkingPIDFile=/var/run/nginx.pidExecStartPost=/bin/sleep0.1ExecStartPre=/usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.confExecReload=/bin/kill-sHUP$MAINPIDExecStop=/bin/kill-sQUIT$MAINPIDLimitNOFILE=1000000LimitNPROC=1000000LimitCORE=1000000[Install]WantedBy=multi-user.target#内容结束#赋予启动服务权限chmod+x/lib/systemd/system/nginx.service#设置开机启动systemctlenablenginx#设置nginx配置文件,根据自己实际情况vim/usr/local/nginx/conf/nginx.conf#输入以下内容userwwwwww;worker_processesauto;error_log/data/wwwlogs/error_nginx.logcrit;pid/var/run/nginx.pid;worker_rlimit_nofile51200;events{useepoll;worker_connections51200;multi_accepton;}http{includemime.types;default_typeapplication/octet-stream;server_names_hash_bucket_size128;client_header_buffer_size32k;large_client_header_buffers432k;client_max_body_size1024m;client_body_buffer_size10m;sendfileon;tcp_nopushon;keepalive_timeout120;server_tokensoff;tcp_nodelayon;fastcgi_connect_timeout300;fastcgi_send_timeout300;fastcgi_read_timeout300;fastcgi_buffer_size64k;fastcgi_buffers464k;fastcgi_busy_buffers_size128k;fastcgi_temp_file_write_size128k;fastcgi_intercept_errorson;#Gzip Compressiongzipon;gzip_buffers168k;gzip_comp_level6;gzip_http_version1.1;gzip_min_length256;gzip_proxiedany;gzip_varyon;gzip_typestext/xmlapplication/xmlapplication/atom+xmlapplication/rss+xmlapplication/xhtml+xmlimage/svg+xmltext/javascriptapplication/javascriptapplication/x-javascripttext/x-jsonapplication/jsonapplication/x-web-app-manifest+jsontext/csstext/plaintext/x-componentfont/opentypeapplication/x-font-ttfapplication/vnd.ms-fontobjectimage/x-icon;gzip_disable"MSIE [1-6]\.(?!.*SV1)";##Brotli Compression#brotli on;#brotli_comp_level 6;#brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;##If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.#open_file_cache max=1000 inactive=20s;#open_file_cache_valid 30s;#open_file_cache_min_uses 2;#open_file_cache_errors on;######################## default ############################server{listen80;server_name_;access_log/data/wwwlogs/access_nginx.logcombined;root/data/wwwroot/default;indexindex.htmlindex.htmindex.php;#error_page 404 /404.html;#error_page 502 /502.html;location/nginx_status{stub_statuson;access_logoff;allow127.0.0.1;denyall; }location~ [^/]\.php(/|$) {#fastcgi_pass remote_php_ip:9000;fastcgi_passunix:/dev/shm/php-cgi.sock;fastcgi_indexindex.php;includefastcgi.conf; }location~.*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {expires30d;access_logoff; }location~.*\.(js|css)?$ {expires7d;access_logoff; }location~^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {denyall; } }########################## vhost #############################includevhost/*.conf;}#输入内容结束mkdir-p/data/wwwlogs/mkdir-p/data/wwwroot/defaultmkdir-p/usr/local/nginx/conf/vhostvim/data/wwwlogs/access_nginx.logservicenginxstartservicenginxstatus#配置示例# 以官方配置为例server{# for better compatibility it's recommended# to use the same port for quic and httpslisten443http3reuseport;#注意reuseport参数只能在整个nginx配置文件中出现一次,不必每个vhost都使用,否则会报错listen443sslhttp2;ssl_certificatecerts/example.com.crt;ssl_certificate_keycerts/example.com.key;ssl_protocolsTLSv1.3;location/{# required for browsers to direct them into quic portadd_headerAlt-Svc'$http3=":443"; ma=86400';#以下为兼容的http3格式# add_header Alt-Svc 'h3-29=":443"; ma=2592000,h3-28=":443";ma=2592000,h3-27=":443"; ma=2592000,h3-25=":443";ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443";ma=2592000,h3-Q049=":443";ma=2592000,h3-Q048=":443";ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443";ma=2592000,quic=":443"; ma=2592000; v="46,43"'; } }
wget https://github.com/jemalloc/jemalloc/archive/5.2.1.tar.gz
mv 5.2.1.tar.gz jemalloc-5.2.1.tar.gz
tar xvzf jemalloc-5.2.1.tar.gz
cd jemalloc-5.2.1
./autogen.sh
make && make install