好吧,我幾乎放棄了這一點,但是如何禁用Nginx緩存JavaScript文件?我在使用Nginx的Docker容器。當我現在改變JavaScript文件中的內容時,我需要多次重新加載,直到新文件在那裏。爲JavaScript文件禁用nginx緩存
我怎麼知道它是Nginx,而不是瀏覽器/ docker?
瀏覽器:我在命令行上使用curl
來模擬請求併產生相同的問題。另外,我正在使用CacheKiller
插件,並在Chrome開發工具中禁用緩存。
Docker:當我連接到容器的bash,並在更改文件後使用cat
時,我立即得到正確的結果。
我爲sites-enabled
這個(我在另一個計算器線程中)改變了我的nginx.conf
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;
}
然而,重建容器(並確保它在與cat
容器)後,它仍然沒沒有工作。這下面是完整的.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;
}
沒關係,我在生產中進行緩存,只是不在開發中。我會嘗試你的建議 – Musterknabe
陷阱,那麼有道理。 –
我剛剛將你的代碼添加到我的'app.conf'中,但現在nginx甚至不再啓動。當我使用'nginx -t'時,出現錯誤'unknown directive'proxy_no_store「' – Musterknabe