Results 1 to 3 of 3

Thread: Howto Upgrade (refresh) nginx reverse proxy static cache files

  1. #1
    Senior Member t0kneneng's Avatar
    Join Date
    Jul 2008
    Posts
    132
    Thanks
    10
    Thanked 1 Time in 1 Post
    Rep Power
    6

    Default Howto Upgrade (refresh) nginx reverse proxy static cache files

    Hi, I need some help here below is my config on my nginx server. I serve static files js, css, jpeg files. I seems my reverse proxy is not working everything I update my css or other file on my static server I need to clear cache to be able to reflect my new css and images file. How can I prevent to clear cache every now and then and new css, images will be loaded on my cache also once file is being cache no need to load again from the client side. Please let me know what was wrong on below config.


    Nginx.conf
    Code:
    #Run as webuser to minimize permission conflict
    user  nginx nginx;
    
    # For high performance you'll need one worker process per disk spindle
    # but in most cases 1 or 2 is fine.
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log debug;
    pid /var/run/nginx.pid;
    
    events {
            # Max concurrent connections = worker_processes * worker_connections
            # You can increase this past 1024 but you must set the rlimit before starting
            # ngxinx using the ulimit command (say ulimit -n 8192)
    
            worker_connections  1024;
            #Linux performance awesomeness on
            use epoll;
    }
    
    http {
            #server_name_hash_bucket_size 64;
            #Mime stuff
            #Mime-type table
            include       /etc/nginx/mime.types;
            default_type  application/octet-stream;
    
            #Size Limits
            client_max_body_size            200M;
            client_body_buffer_size         8M;
            client_header_buffer_size       128k;
            large_client_header_buffers     1 8k;
    
            #Time out
            client_body_timeout             120;
            client_header_timeout           120;
            send_timeout                    120;
            keepalive_timeout               60 60;
    
            ignore_invalid_headers          on;
            recursive_error_pages           on;
    
            # 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/log/nginx/nginx-client-body/tmp 1 2;
            proxy_cache_path /var/log/nginx/nginx-client-body levels=1:2 keys_zone=main:1024m inactive=7d max_size=1000m;
    
            log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
            #Compression
            gzip on;
            gzip_http_version 1.0;
            gzip_comp_level 2;
            gzip_proxied any;
            gzip_min_length 1100;
            gzip_buffers 16 8k;
            #Some version of IE 6 don't handle compression well on some mime-types, so just diable for them
            gzip_disable "MSIE [1-6].(?!.*SV1)";
            #Set a vary header so downstream proxies don't send cached gzipped content to IE6
            gzip_vary on;
    
            server_tokens   off;
    
            sendfile        on;
            tcp_nopush      on;
            tcp_nodelay     on;
            keepalive_requests 0;
    
      server {
            listen       192.168.0.15:80 default;
    
            server_name  _;
            access_log /var/log/nginx/access.log main;
    
        location / {
            proxy_pass http://127.0.0.1:8080;
            include /etc/nginx/proxy.conf;
        }
      }
      include /etc/nginx/conf.d/*[^~];
    }

    Proxy.conf

    Code:
    proxy_redirect                  off;
    proxy_set_header                Host            $host;
    proxy_set_header                X-Real-IP       $remote_addr;
    proxy_set_header                X-Forwarded-For $proxy_add_x_forwarded_for;
    
    proxy_cache                     main;
    proxy_cache_key                 backend$request_uri;
    proxy_cache_valid               200 301 302 20m;        # Cache pages for 20mins
    proxy_cache_valid               200 304 7d;                     # Cache pages for 7day
    proxy_cache_valid               301 302 1h;                     # Cache pages for 1 hour
    proxy_cache_valid               404 403 402 401 504 502 20m;    # Cache Other errors for 20mins
    proxy_cache_valid               any 15m;                        # Cache others for 15 minute
    proxy_cache_valid               404 1m;                         # Cache errors for 1 minute
    proxy_cache_use_stale           error timeout invalid_header updating;
    
    proxy_connect_timeout           180;
    proxy_send_timeout              180;
    proxy_read_timeout              180;
    
    proxy_buffers                   8 16k;
    proxy_buffer_size               32k;
    proxy_busy_buffers_size         64k;
    proxy_temp_file_write_size      64k;
    
    proxy_pass_header               Expires;
    proxy_pass_header               Cache-Control;
    proxy_pass_header               Last-Modified;
    proxy_pass_header               ETag;
    proxy_pass_header               Content-Length;
    virtual.conf
    Code:
    server {
            listen 192.168.0.15:80;
            server_name _;
            server_name_in_redirect off;
            resolver 127.0.0.1;
            root /var/www/html/public_html;
            access_log /var/log/nginx/access.log main;
    
            if (-f $request_filename) {
                    break;
                    }
    
            location / {
                    proxy_pass http://127.0.0.1:8080;
                    include /etc/nginx/proxy.conf;
            }
    
            location ^~ (jpeg|gif|png|ico|flv|hqx|cpt|csv|text|bin|dms|lha|lzh|exe|clas|psd|so|sea|dll|oda|pdf|ai|eps|ps|smi|smil|mif|xls|ppt|wbxml|wmlc|dcr|dir|dxr|dvi|gtar|gz|php|php4|php3|phps|js|swf|sit|tar|tgz|xhmtl|xht|zip|mid|midi|mpga|mp2|mp3|aif|aifc|ram|rm|rpm|ra|rv|wav|bmp|jpe|tiff|tif|css|html|htm|shtml|txt|log|rtx|rtf|xml|xsl|mpeg|mpg|mpe|qt|mov|avi|movie|doc|docx|xlsx|xl|eml|ttf)$ {
                    expires 30d;
                    proxy_cache main;
            }
    }

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,498
    Thanks
    17
    Thanked 788 Times in 506 Posts
    Rep Power
    10

    Default

    You are caching it for 30d. So it will not get removed automatically. What you can do is, make changes to server side program itself. You can pass a version number or some sort of random number to refresh the media files (again you need to detect those changes on fly). For example url
    Code:
    http://example.com/style.css
    Can be severed as
    Code:
    http://example.com/style.css?v=1
    http://example.com/style.css?5353535
    Other option is to just delete files from /var/log/nginx/nginx-client-body
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. The Following User Says Thank You to nixcraft For This Useful Post:

    t0kneneng (22nd June 2011)

  4. #3
    Senior Member t0kneneng's Avatar
    Join Date
    Jul 2008
    Posts
    132
    Thanks
    10
    Thanked 1 Time in 1 Post
    Rep Power
    6

    Default

    Quote Originally Posted by nixcraft View Post
    You are caching it for 30d. So it will not get removed automatically. What you can do is, make changes to server side program itself. You can pass a version number or some sort of random number to refresh the media files (again you need to detect those changes on fly). For example url
    Code:
    http://example.com/style.css
    Can be severed as
    Code:
    http://example.com/style.css?v=1
    http://example.com/style.css?5353535
    Other option is to just delete files from /var/log/nginx/nginx-client-body
    thanks nix for your explanation... very much helpful...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Reverse proxy nginx problem
    By mschipperheyn in forum Proxy Servers
    Replies: 2
    Last Post: 15th February 2011, 12:52 AM
  2. How to upgrade Nginx?
    By t0kneneng in forum Proxy Servers
    Replies: 2
    Last Post: 28th December 2010, 06:50 AM
  3. Nginx Reverse proxy error 4xx and 5xx messages
    By t0kneneng in forum Proxy Servers
    Replies: 3
    Last Post: 21st December 2010, 12:47 PM
  4. Webserver and Reverse proxy Nginx
    By t0kneneng in forum CentOS / RHEL / Fedora
    Replies: 3
    Last Post: 22nd November 2010, 05:43 AM
  5. [Solved] Nginx Reverse Proxy Load Balance Configuration For Apache
    By raj in forum Web servers
    Replies: 4
    Last Post: 15th April 2010, 12:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •