nginx缓存灰度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#nginx 版本1.18.0<br>upstream myserver_01 {
    server 127.0.0.1:8080 max_fails=1 fail_timeout=60;
}
 
upstream myserver_02 {
    server x.x.x.x:8080 max_fails=1 fail_timeout=60;
}
 
server {
    listen 80;
    server_name test.test.com;  
    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    rewrite ^(.*)$ https://$host$1;
    root /home/ymbl/front/apps;
 
    location / {
        # 用于配合 browserHistory 使用
        try_files $uri $uri/ /index.html;
 
        # 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
        # rewrite ^/(.*)$ https://preview.pro.loacg.com/$1 permanent;
 
    }
    location /api/ {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;
    }
}
 
#以下属性中,以ssl开头的属性表示与证书配置有关。
server {
    listen 443 ssl;
    #配置HTTPS的默认访问端口为443。
    #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
    #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
    server_name test.test.com; #需要将yourdomain.com替换成证书绑定的域名。
    index index.html index.htm;
    ssl_certificate /usr/local/nginx/conf/cert/test/test.test.com.pem;  #需要将cert-file-name.pem替换成已上传的证书文件的名称。
    ssl_certificate_key /usr/local/nginx/conf/cert/test/test.test.com.key; #需要将cert-file-name.key替换成已上传的证书私钥文件的名称。
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #表示使用的加密套件的类型。
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示使用的TLS协议的类型。
    ssl_prefer_server_ciphers on;
    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
 
 
 
   
  set $black myserver_02;
  set $fe_root /home/test/app/apps;
    if ($http_cookie ~* "version=V1"){
        set $black myserver_01;
        set $fe_root /home/test/app/apps-pre;
    }
 
    if ($http_cookie ~* "version=V2"){
        set $black myserver_02;
    }
 
    root $fe_root;
 
 
 
    location / {
    ## 配置页面不缓存html和htm结尾的文件
    if ($request_filename ~* .*\.(?:htm|html)$) {
        add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
    }  
 
    index  index.html index.htm;
 
        # 用于配合 browserHistory 使用
        try_files $uri $uri/ /index.html;
 
        # 如果有资源,建议使用 https + http2,配合按需加载可以获得更好的体验
        # rewrite ^/(.*)$ https://preview.pro.loacg.com/$1 permanent;
 
    }
 
 
 
 
    location ~ /api/(.*) {
    proxy_pass http://$black/$1;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_send_timeout 3600;
    proxy_read_timeout 3600;
    proxy_connect_timeout 3600;
     
    }
 
#location ~ .*\.(htm|html)?$ {
  #现在改为,增加缓存
 # add_header Cache-Control " no-store";
#}
}

  

posted @   彩虹栗子  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示