D
D
DenisO2012-01-08 19:05:44
Nginx
DenisO, 2012-01-08 19:05:44

Disable caching in Nginx

There is a problem - nginx tightly caches statics. As a result, js/css updates do not appear on the site. Caching is not explicitly specified in the config:

user www-data;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
# log options
log_format main '$host: $remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$gzip_ratio"';
# nginx options
sendfile on;
tcp_nodelay on;
keepalive_timeout 65 20;
# fastcgi
#fastcgi_intercept_errors on;
server {
listen 80;
rewrite ^/article/(.+)$ /?call=article.title&title=$1 break;
location / {
proxy_pass 127.0.0.1 :8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
# Static files location

location ~* \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi |wav|bmp|rtf|js|swf)$
{

if (!-d /home/webmaster/sites/$host ) {
set $cur_host "cms1";
access_log '/var/log/nginx/default.log' main;
}

if (-d /home/webmaster/sites/$host ) {
set $cur_host $host;
access_log '/var/log/nginx/host_access.log' main;
}

root /home/webmaster/sites/$cur_host;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
}

Answer the question

In order to leave comments, you need to log in

10 answer(s)
V
VBart, 2012-01-09
@DenisO

The problem is most likely in VirtualBox. You are not the first to complain about such oddities with him.

D
DenisO, 2012-01-09
@DenisO

The problem is really somewhere between VirtualBox and nginx. I don’t know who is to blame, but changing the virtual machine’s controller type from SATA to IDE helped solve the problem.

A
Arkady, 2012-01-08
@p0is0n

So what about nginx? Clear your browser's cache. Have you looked at server requests? firebug - for example.

D
DenisO, 2012-01-09
@DenisO

forums.virtualbox.org/viewtopic.php?f=3&t=33201
fyi: i had the same problem with nginx. it has the same solution, check 'SendFile' in the nginx docs

C
cadmi, 2012-01-08
@cadmi

Turn on debug log and see what happens.
But in general, the config, of course ... Horror and hell, to put it mildly.

A
Alexey, 2012-01-08
@alexxxst

kill -HUP make the nginx-main process, if it helps, then you need to pick the config, for example, open_file_cache, etc. In general, as already mentioned, the browser or proxy is to blame.

D
DenisO, 2012-01-08
@DenisO

1. sending HUP - after all, it only reloads the config? I did /etc/init.d/nginx restart many times, which in this context is similar to
2. wget host/thisfile.js returns cached js too. This shows that the problem is not in the browser and not in the proxy (it simply does not exist)

I
iddqd3, 2016-07-26
@iddqd3

location ~* \.(?:css|js|txt)$ {
add_header Cache-Control "no-store";
}
Should help

P
Par Mactep, 2018-03-25
@parmactep

Sorry for the necroposting, but I will probably look for the answer to the question myself later.
In the settings of the SATA VirtualBox controller there is a checkbox "I / O caching". This is how she solved the problem.

F
f4llou7, 2018-03-30
@f4llou7

add to nginx config
sendfile off;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question