Skip to content

Commit

Permalink
nginx shouldn't cache css/js, fixes ddev#2404
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jul 22, 2020
1 parent 69358e9 commit f2ab22c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ server {
}

# Media: images, icons, video, audio, HTC
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}

# js and css always loaded
location ~* \.(js|css)$ {
try_files $uri @rewrite;
expires -1;
log_not_found off;
}
include /mnt/ddev_config/nginx/*.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ server {
}

# Media: images, icons, video, audio, HTC
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}

# js and css always loaded
location ~* \.(js|css)$ {
try_files $uri @rewrite;
expires -1;
log_not_found off;
}

# Prevent clients from accessing hidden files (starting with a dot)
# This is particularly important if you store .htpasswd files in the site hierarchy
# Access to `/.well-known/` is allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ server {
}

# Media: images, icons, video, audio, HTC
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}

# js and css always loaded
location ~* \.(js|css)$ {
try_files $uri @rewrite;
expires -1;
log_not_found off;
}

# Prevent clients from accessing hidden files (starting with a dot)
# This is particularly important if you store .htpasswd files in the site hierarchy
# Access to `/.well-known/` is allowed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ server {
}

# Media: images, icons, video, audio, HTC
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}

# js and css always loaded
location ~* \.(js|css)$ {
try_files $uri @rewrite;
expires -1;
log_not_found off;
}

include /mnt/ddev_config/nginx/*.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,18 @@ server {
}

# Media: images, icons, video, audio, HTC
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}

# js and css always loaded
location ~* \.(js|css)$ {
try_files $uri @rewrite;
expires -1;
log_not_found off;
}

include /mnt/ddev_config/nginx/*.conf;
}
21 changes: 19 additions & 2 deletions pkg/ddevapp/webserver_config_packr_assets/nginx-site-magento2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ server {
rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2|json)$ {
location ~* \.(ico|jpg|jpeg|png|gif|svg|swf|eot|ttf|otf|woff|woff2|json)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
Expand All @@ -114,6 +114,16 @@ server {
rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
}
}
location ~* \.(js|css)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires -1;

if (!-f $request_filename) {
rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
}
}

location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
Expand All @@ -136,12 +146,19 @@ server {
deny all;
}

location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
location ~* \.(ico|jpg|jpeg|png|gif|svg|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /get.php$is_args$args;
}
location ~* \.(js|css)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires -1;
try_files $uri $uri/ /get.php$is_args$args;
}

location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ server {
fastcgi_param HTTPS $fcgi_https;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
location ~* \.(png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~* \.(js|css)$ {
expires -1;
log_not_found off;
}

include /mnt/ddev_config/nginx/*.conf;
}

0 comments on commit f2ab22c

Please sign in to comment.