nginx+Ngx_cache_purge配置笔记

本文介绍如何在Nginx中配置Ngx_cache_purge模块实现缓存功能,包括编译安装过程及nginx.conf配置细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx + Ngx_cache_purge

前端的nginx配置与后端差不多,主要是编译安装的时候添加cache模块,基础看后端安装,不多介绍了

1,先解压nginx 和 Ngx_cache_purge,主要不同是安装的时候添加了ngx_cache_purge模块

[root@Nginx-C opt]# tar zxf ngx_cache_purge-2.0.tar.gz 
[root@Nginx-C opt]# tar zxf nginx-1.4.3.tar.gz 
[root@Nginx-C opt]# cd nginx-1.4.3
[root@Nginx-C nginx-1.4.3]# ./configure --user=www --group=www --add-module=../ngx_cache_purge-2.0 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
[root@Nginx-C nginx-1.4.3]# make && make install

2,配置主配置文件 nginx.conf

user  nginx;
worker_processes  4;


error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


pid        logs/nginx.pid;




events {
    use epoll;
    worker_connections  65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    charset  utf-8;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    client_max_body_size 300m;
    server_tokens off;
    fastcgi_intercept_errors on;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  60;
    tcp_nodelay on;
    client_body_buffer_size  512k;


    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout    5;
    proxy_read_timeout       60;
    proxy_send_timeout       5;
    proxy_buffer_size        16k;
    proxy_buffers            4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_temp_path   /opt/app/nginx/proxy_temp;
    proxy_cache_path  /opt/app/nginx/proxy_cache levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=30g;


    gzip  on;
    gzip_min_length     1k;
    gzip_buffers        4 16k;
    gzip_http_version   1.1;
    gzip_comp_level 2;
    gzip_types  text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    server {
         listen  80;
         server_name  download03.pcjoy.cn;
         index index.html index.htm index.php;
         error_page 500 502 503 504 = /error.html;
         error_page 403 404 = /error.html;
         #rewrite     ^   https://$server_name$request_uri? permanent;
         location /{
                root /home/download03.pcjoy.cn/download/;
                #limit_conn addr 2;
                #limit_rate 2048k;
                   }
          }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值