Y
Y
Yuri2021-12-14 15:21:46
Nginx
Yuri, 2021-12-14 15:21:46

Setting cache/buff on nginx for multiple identical sites (java)?

Good afternoon!

There are vps with nginx-proxy on board. This vps has 2 network interfaces: one looks to the Internet, the other to the local area (let's say so).
There are many identical sites (tomcat, java, postgres) spinning in the locale, but with different data. Each of the sites is available on its own domain. The nginx access config is now:
1)

http->https
server {
        listen 80 default_server;
        server_name _;
        return 301 https://$host$request_uri;
}

2)
main

server {
  listen 443 ssl;
  server_name *.domain.ru;
  resolver $IP valid=5m;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_certificate     /etc/ssl/certs/domain.crt;
  ssl_certificate_key /etc/ssl/certs/domain.key;
  ssl_session_cache   shared:SSL:10m;
  ssl_session_timeout 10m;

  gzip on;
  gzip_vary on;
  gzip_min_length 1000;
  gzip_proxied any;
  gzip_comp_level 7;
  gzip_buffers 16 8k;
  gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/png;

  location = / {  
    return 301 https://$host:443/crm;
  }

  location /images {
    root /var/www/html/;
    autoindex off;
    expires 30d;
  }

  location /crm/icons {
    root /var/www/html/;
    autoindex off;
    expires 30d;
  }

  location /crm/images {
    root /var/www/html/;
    autoindex off;
    expires 30d;
  }

  location /crm/img {
    root /var/www/html/;
    autoindex off;
    expires 30d;
  }

  location / {
    proxy_pass       https://$host:443;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}


Those. now, to speed up the work, site statics (the same for all sites) is brought to the nginx proxy level. But the sites receive updates every week through the built-in updater
. And when the static content is updated, you have to manually upload the update to the nginx proxy.
If I disable statics at the nginx level, the problem will be solved. But then another problem will appear - loading speed (these sites are not very optimized)
Will enabling / configuring the nginx proxy config proxy_buffer and / or proxy_cache help me to solve the problem with loading speed of sites (with disabled nginx statics)? If yes, what is the best way to do it?

Important: as you can see from the nginx config, only one config file is used with a redirect to the requested url, but with a request already to your own dns server. So, it’s important to leave this, and configure the nginx proxy to keep one static (the same) for all sites where it redirects.

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-12-14
@karabanov

Something like NGINX Content Caching .
Set it up for /images , /crm/icons , /crm/images , /crm/img . For location / do not configure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question