nginx反向缓存代理不会缓存静态文件

时间:2016-09-04 14:49:27

标签: nginx

我已将nginx配置为apache的反向缓存代理 但它不会缓存静态内容和缓存目录总是很有用 以下是virtualhost的内容

server {
root   /home/xxxx/public_html;
server_name xxxxx.com.xx www.xxxx.com.xx;
error_log  /usr/local/nginx/logs/vhost-error_log warn;
index index.php index.html index.htm;

location ~* \.(png|gif|jpeg|jpg|ico|css|js|xml|swf|pdf|flv|htm|html)$ {
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
proxy_hide_header "Set-Cookie";
root   /home/xxxx/public_html;
proxy_cache nginx-cache;
proxy_cache_valid any 30m;
expires modified +90d;
}

location / {
include /usr/local/nginx/conf/proxy.conf;
proxy_pass   http://xx.xx.xx.xx:8080;
}

}

server { root /home/xxxx/public_html; server_name xxxxx.com.xx www.xxxx.com.xx; error_log /usr/local/nginx/logs/vhost-error_log warn; index index.php index.html index.htm; location ~* \.(png|gif|jpeg|jpg|ico|css|js|xml|swf|pdf|flv|htm|html)$ { proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; proxy_hide_header "Set-Cookie"; root /home/xxxx/public_html; proxy_cache nginx-cache; proxy_cache_valid any 30m; expires modified +90d; } location / { include /usr/local/nginx/conf/proxy.conf; proxy_pass http://xx.xx.xx.xx:8080; }

以下是proxy.conf文件的内容:

proxy_buffering On;
proxy_buffers  3000 6m;
proxy_busy_buffers_size  12m;
proxy_buffer_size 6m;
output_buffers 500 6m;
proxy_cache_key "$host$request_uri";
proxy_ignore_headers "Cache-Control" "Expires";
proxy_pass_header "Set-Cookie";
proxy_cache_min_uses 3;
proxy_max_temp_file_size 0;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 4m;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_ignore_client_abort off;
proxy_intercept_errors off;
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;

以下是nginx.conf的内容 proxy_buffering On; proxy_buffers 3000 6m; proxy_busy_buffers_size 12m; proxy_buffer_size 6m; output_buffers 500 6m; proxy_cache_key "$host$request_uri"; proxy_ignore_headers "Cache-Control" "Expires"; proxy_pass_header "Set-Cookie"; proxy_cache_min_uses 3; proxy_max_temp_file_size 0; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 50m; client_body_buffer_size 4m; proxy_connect_timeout 300s; proxy_read_timeout 300s; proxy_send_timeout 300s; proxy_ignore_client_abort off; proxy_intercept_errors off; proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment; proxy_cache_bypass $http_pragma $http_authorization;

请有人在这帮助我找出为什么缓存目录没有缓存静态内容,如下所示:

user  nobody;
worker_processes 4;
worker_rlimit_nofile 4000;
thread_pool default threads=128 max_queue=65536;
pid        /usr/local/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections  4000;
multi_accept On;
accept_mutex off;
}
http {
aio threads=default;
access_log /dev/null;
error_log /dev/null;
server_tokens Off;
log_format  main '$remote_addr - $remote_user [$time_local]  $status '
                  '"$request" $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
include /usr/local/nginx/conf/mime.types;
default_type  application/octet-stream;
client_body_temp_path /tmp;
proxy_cache_path /home/nginx_cache levels=1:2 keys_zone=nginx-cache:1m max_size=4g inactive=6h use_temp_path=off;
open_file_cache max=3000 inactive=6h;
open_file_cache_valid 6h;
open_file_cache_min_uses 2;
open_file_cache_errors Off;
proxy_temp_path /home/nginx_cache/tmp;
server_names_hash_max_size 512;
server_names_hash_bucket_size 512;
server_name_in_redirect On;
port_in_redirect Off;
tcp_nodelay On;
tcp_nopush On;
sendfile On;
sendfile_max_chunk 512k;
keepalive_timeout 30;
keepalive_requests 100000;
reset_timedout_connection On;
if_modified_since before;
gzip On;
gzip_http_version 1.1;
gzip_buffers 16 8k;
gzip_comp_level 4;
gzip_disable msie6;
gzip_min_length 10;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript application/javascript text/javascript application/atom+xml application/xml application/xml+rss text/xml image/x-icon text/x-js application/xhtml+xml image/svg+xml;
gzip_vary on;
server {
server_name xx.xx.com;
root /usr/local/nginx/html;
listen xx.xx.xx.xx:80 ;
location / {
include /usr/local/nginx/conf/proxy.conf;
proxy_pass   http://xx.xx.xx.xx:8080;
}
}
include       /usr/local/nginx/conf/vhost.conf;
}

user nobody; worker_processes 4; worker_rlimit_nofile 4000; thread_pool default threads=128 max_queue=65536; pid /usr/local/nginx/logs/nginx.pid; events { use epoll; worker_connections 4000; multi_accept On; accept_mutex off; } http { aio threads=default; access_log /dev/null; error_log /dev/null; server_tokens Off; log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; client_body_temp_path /tmp; proxy_cache_path /home/nginx_cache levels=1:2 keys_zone=nginx-cache:1m max_size=4g inactive=6h use_temp_path=off; open_file_cache max=3000 inactive=6h; open_file_cache_valid 6h; open_file_cache_min_uses 2; open_file_cache_errors Off; proxy_temp_path /home/nginx_cache/tmp; server_names_hash_max_size 512; server_names_hash_bucket_size 512; server_name_in_redirect On; port_in_redirect Off; tcp_nodelay On; tcp_nopush On; sendfile On; sendfile_max_chunk 512k; keepalive_timeout 30; keepalive_requests 100000; reset_timedout_connection On; if_modified_since before; gzip On; gzip_http_version 1.1; gzip_buffers 16 8k; gzip_comp_level 4; gzip_disable msie6; gzip_min_length 10; gzip_proxied any; gzip_types text/plain text/css application/json application/x-javascript application/javascript text/javascript application/atom+xml application/xml application/xml+rss text/xml image/x-icon text/x-js application/xhtml+xml image/svg+xml; gzip_vary on; server { server_name xx.xx.com; root /usr/local/nginx/html; listen xx.xx.xx.xx:80 ; location / { include /usr/local/nginx/conf/proxy.conf; proxy_pass http://xx.xx.xx.xx:8080; } } include /usr/local/nginx/conf/vhost.conf; }

请大家接受我最诚挚的问候,

0 个答案:

没有答案