Ok, tôi gần như đã từ bỏ việc này, nhưng làm cách nào để vô hiệu bộ nhớ đệm từ Nginx cho các tệp JavaScript? Tôi đang sử dụng một container docker với Nginx. Khi tôi bây giờ thay đổi một cái gì đó trong tập tin JavaScript, tôi cần nhiều tải lại cho đến khi tập tin mới có.Tắt bộ nhớ cache nginx cho các tệp JavaScript
Làm cách nào để biết đó là Nginx chứ không phải trình duyệt/đế cắm?
Trình duyệt: Tôi đã sử dụng curl
trên dòng lệnh để mô phỏng yêu cầu và có cùng vấn đề. Ngoài ra, tôi đang sử dụng plugin CacheKiller
và đã tắt bộ nhớ cache trong Công cụ dành cho Chrome Dev.
Đế cắm: Khi tôi kết nối với hộp đựng của thùng chứa và sử dụng cat
sau khi thay đổi tệp, tôi nhận được kết quả chính xác ngay lập tức.
tôi đã thay đổi tôi nginx.conf
cho sites-enabled
này (mà tôi tìm thấy trong một thread stackoverflow)
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {
# clear all access_log directives for the current level
access_log off;
add_header Cache-Control no-cache;
# set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years
expires 1s;
}
Tuy nhiên, sau khi xây dựng lại các container (và đảm bảo nó trong container với cat
), nó vẫn didn 't làm việc. Ở đây là hoàn tất các .conf
server {
server_name app;
root /var/www/app/web;
# Redirect to blog
location ~* ^/blog {
proxy_set_header Accept-Encoding "";
sub_filter 'https://testproject.wordpress.com/' '/blog/';
sub_filter_once off;
rewrite ^/blog/(.*) /$1 break;
rewrite ^/blog/break;
proxy_pass https://testproject.wordpress.com;
}
# Serve index.html only for exact root URL
location/{
try_files $uri /app_dev.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app_dev.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|xml|html|htm)$ {
# clear all access_log directives for the current level
access_log off;
add_header Cache-Control no-cache;
# set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years
expires 1s;
}
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log;
}
Đó là okay cho tôi để cache nó trong sản xuất, không phát triển. Tôi sẽ thử đề xuất của bạn – Musterknabe
Gotcha, có ý nghĩa sau đó. –
Tôi vừa thêm mã của bạn vào 'app.conf', tuy nhiên bây giờ nginx không còn bắt đầu nữa.Khi tôi sử dụng 'nginx -t' tôi nhận được lỗi 'chỉ thị không xác định' proxy_no_store" ' – Musterknabe