当前位置 博文首页 > li5672的专栏:Nginx 配置反向代理和缓存

    li5672的专栏:Nginx 配置反向代理和缓存

    作者:[db:作者] 时间:2021-08-30 16:04

    Nginx 反向代理

    upstream tomcats {
      server 127.0.0.1:8001;
      server 127.0.0.1:8002;
      server 127.0.0.1:8003;
    }
    # 要定义在http模块之内,server模块之外
    
    server {
           
           listen 80 ;
         
           location / {
               proxy_pass_header Server;
               proxy_set_header Host $http_host;
               proxy_set_header X-Real-IP $remote_addr;
               proxy_set_header X-Scheme $scheme;
               proxy_pass http://tomcats;
            }
      }                                                                                                          
    

    缓存设置

    proxy_cache_path /opt/app/cache levels=1:2 keys_zone=lzz_cache:10m max_size=10g inactive=60m use_temp_path=off;
    
    server {
    
       location / {
         expires      1h;
         proxy_pass_header Server;
         proxy_set_header Host $http_host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Scheme $scheme;
         proxy_pass http://tomcats;
         proxy_cache lzz_cache;
         proxy_cache_valid 200 304 1m;
         proxy_cache_valid any 10m;
         proxy_cache_key $host$uri$is_args$args;
         add_header Nginx-Cache "$upstream_cache_status";
         proxy_next_upstream error timeout invalid_header http_500http_502 http_503 http_504;
    
      }
    
    }
    
    
    cs
    下一篇:没有了