How to clear the cache of nginx?
I had the exact same problem - I was running my nginx in Virtualbox. I did not have caching turned on. But looks like sendfile
was set to on
in nginx.conf
and that was causing the problem. @kolbyjack mentioned it above in the comments.
When I turned off sendfile
- it worked fine.
This is because:
Sendfile is used to ‘copy data between one file descriptor and another‘ and apparently has some real trouble when run in a virtual machine environment, or at least when run through Virtualbox. Turning this config off in nginx causes the static file to be served via a different method and your changes will be reflected immediately and without question
It is related to this bug: https://www.virtualbox.org/ticket/12597
nginx cache folder is empty
proxy_cache
take effect only when nginx configured a reverse proxy directive proxy_pass
.
To cache fastcgi contents you could follow this doc, replace proxy_cache
with the fastcgi_cache
serie directives.
How do you clear the cache for static files on nginx proxy server
You can update your javascript file with adding the latest version with your file name, which is something like this.
<script src="yourfile.js?v12" > </script>
Here is the ?v12
the version of file you can add.
Every time you edit the javascript file, you can update it like ?v13
, ?v14
, ?v15
so on.
<script src="yourfile.js?v13" > </script>
<script src="yourfile.js?v14" > </script>
<script src="yourfile.js?v13" > </script>
That's how your javascript is not cached in browser.
Nginx server (not showing changes) - Delete cache?
First, css is something that the client caches, not the server. You should clear your browser's cache to see your css changes. Furthermore, browser caching is a common problem in css and javascript development. Luckily, you can take advantage of elixir, which ships with laravel 5.1, to prevent browsers caching your assets.
Visit the docs for more info on laravel elixir.
http://laravel.com/docs/5.1/elixir#versioning-and-cache-busting
Second, laravel gives us a convenient command to clear your server's cache:
php artisan cache:clear
UPDATE:
server {
listen 80;
server_name example.com;
root "/usr/share/nginx/app/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/app-error.log error;
client_max_body_size 100m;
include hhvm.conf;
location ~ /\.ht {
deny all;
}
}
server {
listen 80;
server_name beta.example.com;
root "/usr/share/nginx/beta/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/app-error.log error;
client_max_body_size 100m;
include hhvm.conf;
location ~ /\.ht {
deny all;
}
}
Disable nginx cache for JavaScript files
I have the following nginx virtual host (static content) for local development work to disable all browser caching:
server {
listen 8080;
server_name localhost;
location / {
root /your/site/public;
index index.html;
# kill cache
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache';
if_modified_since off;
expires off;
etag off;
}
}
No cache headers sent:
$ curl -I http://localhost:8080
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Mon, 24 Jul 2017 16:19:30 GMT
Content-Type: text/html
Content-Length: 2076
Connection: keep-alive
Last-Modified: Monday, 24-Jul-2017 16:19:30 GMT
Cache-Control: no-store
Accept-Ranges: bytes
Last-Modified
is always current time.
Note: nginx's $date_gmt
format is not per the HTTP spec (see changing the format).
Related Topics
Applying CSS Styles Only to Certain Elements
Sass: Randomly Pick Background-Image from a List
Top Nav Bar Blocking Top Content of the Page
Sass Invalid CSS Error: "Expected Expression"
Box Shadow on Table Row Not Appearing on Certain Browsers
Image Moves on Hover - Chrome Opacity Issue
Css: Display:Inline-Block and Positioning:Absolute
Percentage Padding/Margin on Grid Item Ignored in Firefox
CSS Rotate a Pseudo :After or :Before Content:""
Responsive CSS Triangle With Percents Width
How to Transition Width of Content With Width: Auto
@Font-Face Anti-Aliasing on Windows and Mac
Difference Between Background and Background-Color
How to Have Css3 Animation to Loop Forever
Changing Font Colour in Textboxes in Ie Which Are Disabled