Answer the question
In order to leave comments, you need to log in
nginx caching how to choose content to cache?
In the site config, when a content type for caching is added to the location, it just stops being displayed on the site. For example, if you add jpg to the line location ~* \.(doc|xls|gz|bz2|zip|rar|js)$, for example, then pictures stop loading... Please tell me where to look?
nginx config:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {worker_connections 65535;}
http {
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent"
log_format bytes '$body_bytes_sent';
access_log /var/log/nginx/access.log main;
proxy_cache_path /var/www/cache/files levels=1:2 keys_zone=full:500m inactive=60m max_size=4096m;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/mime.types;
default_type application/octet-stream;
Site config:
server {
listen 80;
server_name site www.site;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443;
server_name site www.site;
access_log /var/log/nginx/site_access.log;
error_log /var/log/nginx/site_error.log;
ssl on;
ssl_certificate /etc/letsencrypt/live/site/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/site/privkey.pem;
location ~* \.(doc|xls|gz|bz2|zip|rar|js)$ {
add_header Cache-Control "max-age=2592000, public";
proxy_pass http://127.0.0.1:81;
proxy_cache full;
proxy_cache_valid 200 60m;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location / {
proxy_pass 127.0.0.1:81/;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_connect_timeout 60;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_redirect off;
proxy_set_header Connection close;
proxy_pass_header Content-Type;
proxy_pass_header Content-Disposition;
proxy_pass_header Content-Length;
}
location @fallback {
proxy_pass http://127.0.0.1:81;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question