nginx proxy_cache配置后不生成缓存文件,也不缓存图片,且css,js等报500
nginx.conf
http {
#cache begin
proxy_buffering on;
proxy_cache_valid any 10m;
proxy_cache_path /data/cache levels=1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /data/temp;
proxy_buffer_size 4k;
proxy_buffers 100 8k;
#cache end
upstream upserver {
server 104.149.128.130;
}
include /etc/nginx/conf.d/*.conf;
}
conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.php index.html index.htm;
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)?$ /index.php/$1 last;
break;
}
proxy_pass http://upserver;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache my-cache;
proxy_cache_valid 200 304 12h;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
add_header X-Cache '$upstream_cache_status from $host';
expires 1d;
}
location ~ .+\.php($|/) {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_connect_timeout 300;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k;
include fastcgi_params;
}
location ~ .+\.(php|jsp+cgi) {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://upserver;
}
# location ~ \.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js)$ {
# root /var/www/html/static;
# expires 48h;
# }
# location ~ \.(txt)$ {
# root /var/www/html/data/html;
# expires 24h;
# }
}
相关推荐
Nginx配置负载均衡和缓存详解
#### Nginx作为缓存服务器Nginx还可以用作缓存服务器,用于存储静态资源,如图片、CSS和JavaScript文件等。通过缓存这些资源,可以显著减少后端服务器的压力,提高用户访问速度。
nginx配置文件-magent
Nginx的配置需要考虑到Magento的特性,如静态文件(图片、CSS、JS)的处理、URL重写、缓存策略等。3.
nginx 笔记和资料
200 301 302 60m; proxy_cache_bypass $http_pragma; proxy_cache_revalidate on;}```这会为指定类型的文件启用缓存,并设置有效期
Nginx header模块缓存配置原理与CentOS 8实战避坑指南
浏览器缓存是Web性能优化的基础能力,其核心依赖HTTP响应头(如Cache-Control、ETag)的正确生成与传递。Nginx通过header模块控制响应头,但add_header指令存在状态码隔离、作用域继承断裂等底层机制限制,导致配置看似生效却无法触发304验证或内存缓存。在CentOS 8环境中,OpenSSL 1.1.1k、systemd 239及SELinux策略进一步加剧了缓存链路的不确定性。本文聚焦Nginx header模块的本质原理,结合map动态映射、proxy_hide_head
HTTP缓存五层决策机制与实战配置指南
HTTP缓存是Web性能与数据一致性的核心基础设施,其本质是一套遵循RFC 7234的分布式状态机,覆盖浏览器内存/磁盘缓存、代理服务器、CDN边缘节点及源站反向代理五层。它通过Cache-Control指令集(如max-age、s-maxage、immutable)、ETag/Last-Modified协商机制和Vary头实现资源新鲜度判定与上下文感知。正确配置不仅能将首屏TTFB降低80%、CDN回源率压至3%以下,更是防止敏感数据泄露、保障API实时性、支撑高并发业务的关键防线。本文聚焦中高级开发者真


