- 配置列表清单
主机名 IP地址 用途 tracker_group1 192.168.47.203 tracker服务器group1 tracker_group2 192.168.47.204 tracker服务器group2
ngx_cache_purge作用
-
下载地址
-
用途
ngx_cache_purge是第三方模块,用于清理nginx内置模块(proxy_cache)缓存。就像CDN的清理缓存的url命令一样
安装Nginx
-
创建用户www来启动执行nginx进程
useradd www
-
安装编译所需的依赖包
yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
-
nginx编译添加ngx_cache_purge模块
cd nginx-1.17.1./configure --user=www --group=www --prefix=/application/nginx-1.15.2 --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/root/ngx_cache_purge-master
编译参数可根据实际情况而配置,只需要在编译的时候添加ngx_cache_purge module模块即可
-
安装
make && make install
-
软链接
ln -s /application/nginx-1.15.2 /application/nginx
-
配置nginx负载均衡和缓存
user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; use epoll; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; #gzip on; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 300m; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:200m max_size=1g inactive=30d; proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp; upstream fdfs_group1 { server 192.168.47.205:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.47.206:8888 weight=1 max_fails=2 fail_timeout=30s; } upstream fdfs_group2 { server 192.168.47.207:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.47.208:8888 weight=1 max_fails=2 fail_timeout=30s; } server { listen 8000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location /group1/M00 { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group1; expires 30d; } location /group2/M00 { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; proxy_pass http://fdfs_group2; expires 30d; } location ~/purge(/.*) { allow 127.0.0.1; allow 192.168.47.0/24; deny all; proxy_cache_purge http-cache $1$is_args$args; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
-
创建缓存使用目录
mkdir -p /fastdfs/cache/nginx/proxy_cache mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp
-
防火墙开启8000端口