nginx无法正确缓存的乘客

问题描述:

当我在网站上进行操作时,比如注册或创建记录,nginx会在操作前呈现页面的缓存版本,但是当我刷新时,我会看到正确的页面。nginx无法正确缓存的乘客

我有最新的客运nginx的运行与CONF:

pid /opt/nginx/logs/nginx.pid; 
# Run as the nginx user 
user root; 
worker_processes 2; 

error_log /opt/nginx/logs/error.log notice; 

events { 
    worker_connections 1024; 
    use epoll; 
} 

http { 
    server_names_hash_bucket_size 64; 
    # More Linux performance awesomeness 
    tcp_nopush on; 
    tcp_nodelay off; 

    # Where to store the body of large client requests on disk 
    # NGINX will stream this to disk before posting it to your Mongrels, 
    # preventing slow clients tying up your app. 
    client_body_temp_path /var/spool/nginx-client-body 1 2; 

    # Max size of a request from a client (usually a POST). This will 
limit 
    # the size of file uploads to your app 
    client_body_buffer_size 8k; 
    client_header_buffer_size 1k; 
    client_max_body_size 1k; 
    large_client_header_buffers 4 8k; 

    ## Timeouts 
    client_body_timeout 5; 
    client_header_timeout 5; 
    keepalive_timeout 5 5; 
    send_timeout 5; 

    ## General Options 
    ignore_invalid_headers on; 
    limit_zone carboncal $binary_remote_addr 1m; 
    recursive_error_pages on; 
    sendfile on; 
    server_name_in_redirect off; 
    server_tokens off; 

    # passenger loading stuff 
    passenger_root 
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2; 
    passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p136/ruby; 

    include /opt/nginx/conf/mime.types; 
    default_type application/octet-stream; 

    ## Compression 
    gzip on; 
    gzip_buffers 16 8k; 
    #compression level between 1 and 9 
    gzip_comp_level 9; 
    gzip_http_version 1.0; 
    gzip_min_length 0; 
    gzip_types text/plain text/html text/css image/x-icon image/bmp application/x-javascript text/xml application/xml application/xml+rss text/javascript ; 
    gzip_vary on; 
    gzip_proxied any; 
    # Some version of IE 6 don't handle compression well on some mime-types, so just disable them 
    gzip_disable "MSIE [1-6].(?!.*SV1)"; 


    # Send along useful info to the mongrels 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_redirect off; 
    proxy_max_temp_file_size 0; 

    ## Log Format 
    log_format main '$remote_addr $host $remote_user [$time_local] "$request" ' 
        '$status $body_bytes_sent "$http_referer" "$http_user_agent" "$gzip_ratio"'; 


    access_log /opt/nginx/logs/access.log main; 

    # virtual hosting 
    server { 
    access_log /opt/nginx/logs/test_server.access.log main buffer=32k; 
    error_log /opt/nginx/logs/test_server.error.log info; 
    expires 6h; 
    listen 80 default rcvbuf=64k backlog=128; 
    root /opt/apps/website/public; 
    server_name website.com www.website.com; 
    passenger_enabled on; 
if (-f $document_root/system/cache/$uri/index.html) { 
    rewrite (.*) /system/cache/$1/index.html break; 
} 

if (-f $document_root/system/cache/$uri.html) { 
    rewrite (.*) /system/cache/$1.html break; 
} 
    } 
} 

我猜问题与重写做。我尝试了各种重写规则,但仍然没有。

这是我期望发生的事情。除非我错了(我可能已经很长时间了,因为我查看了Nginx配置),你的配置是将expires标头设置为6小时。

我怀疑刷新只是强制页面下载非缓存版本。您可能只想将公开内容缓存6个小时。

+0

太棒了,修正了它!让我无需理解就可以从Internet复制代码。 – 2011-02-05 02:25:39