как настроить Nginx для кэширования подпути? - PullRequest
0 голосов
/ 20 июня 2019

Я хочу настроить nginx для кэширования некоторых моих подпутных элементов, но не всех. В частности, я бы хотел кэшировать файлы CSS, JPEG, PNG и GIF для таких вещей, как графана на уровне обратного прокси. Я видел много примеров конфигураций для кэширования, но все они разные, и все они предназначены для глобальных конфигураций, которые я на самом деле не хочу глобально кэшировать для каждого из моих подпутей. Любая помощь будет полезна.

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;
  }
}
...