如何设置Nginx缓存子路径?

时间:2019-06-20 15:59:57

标签: nginx proxy nginx-reverse-proxy nginx-config

我想设置nginx来缓存我的一些子路径项,但不是全部。具体来说,我想在反向代理级别缓存CSS,JPEG,PNG和GIF文件,例如grafana。我已经看到了许多用于缓存的示例配置,但是它们都是不同的,并且它们都是针对全局配置的,我实际上并不想全局地缓存我的每个子路径。任何帮助都会有所帮助。

server {
      listen      80;
      ## set up domain name here ##
      server_name example.com;
      access_log off;
      ##** nginx redirect ALL http requests to https ** ##
      return      301 https://$server_name$request_uri;
}

 server {
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name example.com;
  resolver 192.168.86.9 valid=10s;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


  location / {
      proxy_pass http://192.168.86.31/;
      proxy_set_header   X-Real-IP $remote_addr;
      proxy_set_header   Host      $http_host;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
  }
  location /sonarr {
      proxy_pass http://192.168.86.29:8989;
      proxy_set_header Accept-Encoding "";
      sub_filter
      '</head>'
      '<link rel="stylesheet" type="text/css" href="https://gilbn.github.io/theme.park/CSS/themes/orgarr-plex.css">
      </head>';
      sub_filter_once on;
  }
  location /radarr {
      proxy_pass http://192.168.86.29:7878;
      proxy_set_header Accept-Encoding "";
      sub_filter
      '</head>'
      '<link rel="stylesheet" type="text/css" href="https://gilbn.github.io/theme.park/CSS/themes/orgarr-plex.css">
      </head>';
      sub_filter_once on;
  }
  location /grafana/ {
      proxy_pass http://192.168.86.44:5000/;
      proxy_set_header X-Forwarded-Host $server_name;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Accept-Encoding "";
      sub_filter
      '</head>'
      '<link rel="stylesheet" type="text/css" href="https://gilbn.github.io/theme.park/CSS/themes/graforg.css">
      </head>';
      sub_filter_once on;
  }
  location /netdata {
      proxy_pass http://192.168.86.35:80/netdata/;
      proxy_set_header Accept-Encoding "";
      sub_filter
      '</head>'
      '<link rel="stylesheet" type="text/css" href="https://gilbn.github.io/theme.park/CSS/themes/netorg-dark.css">
      </head>';
      sub_filter_once on;
  }
   location /monitor {
      proxy_pass http://192.168.86.37/monitorr;

  }
   location /map/ {
            rewrite ^/map/(.*) /$1 break;
            proxy_pass http://192.168.86.30:8123;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host$uri;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
  }
   location /ombi {
            proxy_pass http://192.168.86.29:5000;
  }
}

0 个答案:

没有答案