2

I'm running nginx on a linux ubuntu 12.04 on a AWS machine, and I keep getting weird "caching" (?) issues on my production server. When I deploy new .css, .html, .js code - some files update, and others don't, and I get a weird mixed behavior between them. (e.g. the app works weirdly, etc.) If I ask my users to reset their cache (locally), everything works fine. I'd like to figure out a way to not have to ask users to do that!

I have tried changing the nginx configuration settings to keep getting "304" or "not modified" responses for my static files - even though I tried turning off caching, and tried following various stackoverflow posts about how to turn caching off.

Does anyone have any thoughts on what might be the problem? My guesses so far are - maybe it's something aws specific (though I tried turning sendfile off), or one of my other settings is overriding?

I've tried.. How to prevent "304 Not Modified" in nginx? How to clear the cache of nginx? How to disable nginx cache https://serverfault.com/questions/269420/disable-caching-when-serving-static-files-with-nginx-for-development

  • and nothing's worked.

Tried sendfile off; sendfile on; setting "no cache" as well as setting a cache and having it expire in 1s.. (And running "sudo service nginx restart" between config file changes) - but still no luck. Every time, no matter what - I keep getting "304 - file not modified" headers; and my users

My (full) current config:


user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    add_header Cache-Control no-cache;
    sendfile off; # Virtualbox Issue
    expires 0s;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

And inside my /sites-enabled/ folder,

upstream app_server {
        server XX.XX.XX.XX:XXXX fail_timeout=0;
}


    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;

            if (!-f $request_filename) {
                    proxy_pass http://app_server;
                    break;
            }
    }


# Virtualbox & Nginx Issues
sendfile  off;

# Set the cache to expire - always (no caching)
location ~* \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    expires 1s;

    }

Any thoughts?

Thanks so much!!

Community
  • 1
  • 1
Boris T
  • 21
  • 1
  • 3

0 Answers0