これはほとんど気にしないですが、JavaScript用のNginxファイルからのキャッシュを無効にするにはどうしたらいいですか?私はNginxでドッカーコンテナを使用しています。 JavaScriptファイルで何かを変更すると、新しいファイルがそこに来るまで、複数のリロードが必要になります。JavaScriptファイル用のnginxキャッシュを無効にする
Nginxでブラウザ/ドッカーではないことをどのように知っていますか?
ブラウザ:コマンドラインでcurl
を使用してリクエストをシミュレートし、同じ問題が発生しました。また、CacheKiller
プラグインを使用しており、Chrome Dev Toolsでキャッシュを無効にしています。
ドッカー:ファイルを変更した後、コンテナのbashに接続してcat
を使用すると、すぐに正しい結果が得られます。
私はしかし、コンテナを再構築(と、それはcat
と容器の中にあります確認して)した後、それはまだdidnの(私は別の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;
}
からsites-enabled
のための私のnginx.conf
を変更仕事はありません。これは、ここにexpires
とadd_header
ディレクティブは、ファイルをキャッシュnginxのに影響を与えない完全な.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
Gotcha、その後意味があります。 –
あなたのコードを 'app.conf'に追加しましたが、nginxはもはや起動しません。'nginx -t'を使うと、' unknown directive "というエラーが出ます。proxy_no_store" ' – Musterknabe