我正在使用 Nginx 作为带有 ngx_http_memcached_module 的负载均衡器,并且安装了 Memcached 服务器,我想将它与 Nginx 连接,以使其从 Memcached 服务器获取响应。
负载均衡器.conf(Nginx)
upstream backend {
# least_conn;
server 192.168.222.130 weight=1 max_fails=3 fail_timeout=30s;
server 192.168.222.131 weight=2 max_fails=3 fail_timeout=30s;
}
proxy_buffer_size 1k;
proxy_buffers 24 4k;
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=backcache:8m max_size=50m;
proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
server {
listen 80;
location / {
proxy_cache backcache;
proxy_cache_bypass $http_cache_control;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_pass http://backend;
}
location /wp-admin {
proxy_pass http://192.168.222.130/wp-login.php;
}
}
Memcached 配置:
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="192.168.222.139"
Nginx 示例配置来自官方网站
但是我不明白每个线的作用是什么,无法将其应用到我的服务器上。
server {
location / {
set $memcached_key "$uri?$args";
memcached_pass host:11211;
error_page 404 502 504 = @fallback;
}
location @fallback {
proxy_pass http://backend;
}
}