首页 > 系统相关 >nginx cache test.md

nginx cache test.md

时间:2024-04-29 13:33:36浏览次数:16  
标签:header cache purge nginx proxy && test

Nginx Cache 简要配置

# 使用 CentOS 7 作为基础镜像
FROM centos:7

# 安装依赖
RUN yum -y update && \
    yum -y install epel-release && \
    yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel

# 下载 Nginx 和 ngx_cache_purge 模块
RUN curl -O http://nginx.org/download/nginx-1.18.0.tar.gz && \
    tar -zxvf nginx-1.18.0.tar.gz && \
    curl -L https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz | tar zx

RUN groupadd -r nginx && \
    useradd -r -g nginx -d /var/cache/nginx -s /sbin/nologin nginx


# 编译 Nginx 与 ngx_cache_purge 模块
RUN cd nginx-1.18.0 && \
    ./configure --with-http_ssl_module  		--user=nginx \
                                        		--group=nginx \
     --add-module=../ngx_cache_purge-2.3 && \
    make && make install


# 设置环境变量,使 nginx 命令可用
ENV PATH="/usr/local/nginx/sbin:$PATH"

# 清理安装包和缓存
RUN yum clean all && \
    rm -rf /nginx-1.18.0.tar.gz /nginx-1.18.0 /ngx_cache_purge-2.3.tar.gz /ngx_cache_purge-2.3

# 暴露 80 端口
EXPOSE 80

RUN mkdir -p /data/nginx/cache

COPY DockerfileNcnginx.conf /usr/local/nginx/conf/nginx.conf

# 使用 Nginx 前台运行
CMD ["nginx", "-g", "daemon off;"]

DockerfileNcnginx.conf

user nginx nginx;
# worker_processes  auto;
worker_processes  1;

# error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

	upstream my_backend {
                server www.test.com;
	}
    #gzip  on;

    proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off;

    server {
        listen       80;
        server_name  localhost;
      location ~/purge_cache(/.*) {
    #             allow 127.0.0.1;
    #             deny all;
                proxy_cache_purge my_cache $1;

                add_header X-Cache-xxxxxxxxxxxxx  $1 always;
        }
        location /bbs/ {
            proxy_pass http://my_backend;
            proxy_set_header Host "www.test.com";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_cache_key $uri;
            proxy_cache my_cache;
            proxy_cache_revalidate on;
            proxy_cache_min_uses 1;
            proxy_cache_use_stale error timeout updating;
            proxy_cache_lock on;

# 忽略后端的 Cache-Control 和 Expires 头部
            proxy_ignore_headers Cache-Control Expires;

            # 无论后端说什么,都缓存所有200状态码的响应60分钟
            proxy_cache_valid 200 60m;
            # 添加此行来显示缓存状态
            add_header X-Cache-Status11 $upstream_cache_status always;
            add_header X-Cache-DDDDD  $uri always;
        }



        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }
}


标签:header,cache,purge,nginx,proxy,&&,test
From: https://www.cnblogs.com/zbw911/p/18165454

相关文章

  • AtCoder Beginner Contest 351
    B-SpottheDifference难度:⭐题目大意给定两个矩阵,找不同解题思路数据很小,暴力就行;神秘代码#include<bits/stdc++.h>#defineintunsignedlonglong#defineIOSios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#defineendl'\n'usingnamespa......
  • LruCache源码解析
    最近被问到LruCache原理一直觉得很简单的东西猛然一想,卧槽忘了,赶紧翻开源码瞧瞧!1、首先构造lrucache的时候会新建一个linkedHashMap来作为存储容器publicLruCache(intmaxSize){if(maxSize<=0){thrownewIllegalArgumentException("maxSize<=......
  • yum安装mysql报错--您可以尝试添加 --skip-broken 选项来解决该问题 清除缓存命令
    yum安装mysql报错--您可以尝试添加--skip-broken选项来解决该问题    安装mysql时,如果安装报错,首先删除缓存,    1、清除缓存  yumcleancache    2、重新加载  yummakecache    3、重新安装  yuminstallmysql    此......
  • nginx最新版编译(1.26.0)
    1.下载nginx源码包https://nginx.org/en/download.html 2.下载编译nginx依赖包,可根据自己需求进行下载#pcre(处理正则表达式)http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip#zlib(Nginx使用zlib来实现对HTTP响应内容的压缩,以提高网络传输效......
  • AtCoder Beginner Contest 208 E
    E-DigitProducts点击查看代码map<int,int>f[20];voidsolve(){intn,k;cin>>n>>k;autos=to_string(n);intm=s.size();function<int(int,int,int,int)>dfs=[&](inti,intlimit,intis_num,intmul)->int{if(i......
  • Nginx反向代理的好处
    负载均衡:好处:负载均衡可以将传入的请求分发到多个后端服务器,从而提高系统的性能和可靠性,同时避免单个服务器过载。例子:假设有一个电子商务网站,每天有大量用户同时访问,使用Nginx的负载均衡功能可以将请求分发到多个商品服务器上,确保每个用户都能够快速访问到商品信息,而不会因......
  • Time test
    卡卡网正式开通2009年5月卡卡网(www.webkaka.com)建立于2009年5月,本站旨在为广大网站建设人员提供专业的网站测速和优化服务,以及为广大网民提供网络速度测试服务。卡卡网当日独立IP首次超过20002009年8月......
  • pytest lastfailed原理
    相信很多使用pytest的,都知道pytest有运行上次失败用例的参数,如下:--lf,--last-failedrerunonlytheteststhatfailedatthelastrun(orallifnonefailed)--ff,--failed-firstrunalltests,butrunthelastfailuresfirst.Thism......
  • 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming Contest
    A.MaximumElementInAStack按照题目模拟就好,栈内的最大值可以维护单调栈解决。#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;usingui32=unsignedint;ui32SA,SB,SC;ui32rng61(){SA^=SA<<16;SA^=SA>>5;SA^......
  • python修改pip的cache默认文件夹
    之前一直没管,默认会在c盘,越来越大修改pip.ini之前写过一篇关于pip.ini的文章https://www.cnblogs.com/qcy-blog/p/17789058.htmlcache文件夹要存在[global]cache-dir=D:\pip\cache查看是否更改成功pipcachedir......