前言
在用 Nginx+Redis Cache 给 WordPress 提速 中在 Linux 系统上借助 Openresty 默认集成的拓展实现了 Nginx —— SRcache 拓展 —— Redis 的快速响应,其实我们在 Win 下借助 Openresty 依旧可以实现这个步骤!
首先,因为有 Upupw 的 WNMP(Win + Nginx + MariaDB + PHP7 + Redis)的一键包和 Openresty 的 Win.32 包,所以实现这些都并不复杂,至少最难的部分已经有人帮我们搞定了。
内容
upupw
一、进入 www.upupw.net/Nginx/ 下,我们选择自己所需要的对应 PHP 版本的包下载,一般来说,选择 PHP7 64位的最好啦(前提是你的系统是 64 位)。然后进入下载,解压后即可。
提示:记得先安装 .net 3.5 库!,然后也不要运行!
二、备份 upupw 目录下的 Nginx\conf\下的所有文件,切记,一定要备份。
Openresty
一、进入 openresty.org/cn/download.html下,下载 Win32 字眼的包即可,例如:openresty.org/download/openresty-1.9.15.1-win32.zip
二、解压包内所有的文件都解压到 upupw 目录下的 Nginx\ 替换原有的文件
三、将之前备份的 的 Nginx\conf\下的所有文件重新恢复好。
启动
然后,我们就可以运行 upupw.exe 文件了,输入 s1 启动全部服务即可。
这时候,我们在命令提示符里输入如下,就可以看到 Nginx 是不是 Openresty,和有没有我们所需的 Srcache 拓展了
Microsoft Windows [版本 10.0.10240] (c) 2015 Microsoft Corporation. All rights reserved. C:\Windows\system32>cd C:\mf8.biz\UPUPW\Nginx C:\mf8.biz\UPUPW\Nginx>Nginx -V nginx version: openresty/1.9.15.1 built by gcc 4.9.3 (GCC) built with OpenSSL 1.0.2e 3 Dec 2015 TLS SNI support enabled configure arguments: --prefix=. --with-cc-opt='-O2 -DFD_SETSIZE=1024' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.59 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.30 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.05 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.5 --add-module=../ngx_lua_upstream-0.05 --add-module=../headers-more-nginx-module-0.30 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-cc=gcc --with-ipv6 --sbin-path=nginx.exe --with-ipv6 --with-pcre-jit --with-http_stub_status_module --with-http_realip_module --with-stream --with-stream_ssl_module --with-http_addition_module --with-http_sub_module --with-pcre=/c/agentzh/openresty-1.9.15.1/objs/lib/pcre-8.38 --with-zlib=/c/agentzh/openresty-1.9.15.1/objs/lib/zlib-1.2.8 --with-openssl=/c/agentzh/openresty-1.9.15.1/objs/lib/openssl-1.0.2e --with-select_module --with-http_ssl_module
配置
如何添加虚拟主机这里就不讲了,具体可以参考 upupw 官网的教程。这里介绍一下,如何添加对应的规则。
修改 Nginx\conf 下的 vhost.conf 文件。
这是在一个虚拟主机里的配置信息,可以参考一下:
upstream redis { server 127.0.0.1:6379; keepalive 512; } server { listen 80; server_name test1.mf8.biz alias ; location / { root C:/mf8.biz/UPUPW/vhosts/test.mf8.biz; index index.html index.htm default.html default.htm index.php default.php app.php u.php; include C:/mf8.biz/UPUPW/vhosts/test.mf8.biz/up-*.conf; } autoindex off; include advanced_settings.conf; #include expires.conf; location ~* .*\/(attachment|attachments|uploadfiles|avatar)\/.*\.(php|PHP7|phps|asp|aspx|jsp)$ { deny all; } set $skip_cache 0; if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } location /redis-fetch { internal ; set $redis_key $args; redis_pass redis; } location /redis-store { internal ; set_unescape_uri $key $arg_key ; redis2_query set $key $echo_request_body; redis2_query expire $key 14400; redis2_pass redis; } location ~ .*\.(php|php5)?$ { set $key "nginx-cache:$scheme$request_method$host$request_uri"; try_files $uri =404; srcache_fetch_skip $skip_cache; srcache_store_skip $skip_cache; srcache_response_cache_control off; set_escape_uri $escaped_key $key; srcache_fetch GET /redis-fetch $key; srcache_store PUT /redis-store key=$escaped_key; more_set_headers 'X-Cache $srcache_fetch_status'; more_set_headers 'X-Store $srcache_store_status'; #fastcgi_pass remote_php_ip:9000; fastcgi_pass bakend; fastcgi_pass bakend; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi.conf; } } #server test.mf8.biz end}
重启 Nginx 即可。 剩余步骤可以参考:https://bbs.mf8.biz/nginx-redis-cache-make-wordpress-fast/
何苦用win作服务器。。。
只是练手。 你很难保证你的客户不会作死 一定要求用win