Closed bs-jokri closed 7 years ago
note: One can enable serverside caching for nginx via:
diff --git a/deployment/sw360nginx/docker-entrypoint.sh b/deployment/sw360nginx/docker-entrypoint.sh
index 0b51af5..f3ec720 100755
--- a/deployment/sw360nginx/docker-entrypoint.sh
+++ b/deployment/sw360nginx/docker-entrypoint.sh
@@ -32,9 +32,14 @@ if [ "$NGINX_CERTIFICATE" ] && [ "$NGINX_KEY_PRIV" ]; then
fi
fi
+mkdir -p /data/nginx/cache
+
################################################################################
## generate /etc/nginx/conf.d/nginx-sw360.conf
cat <<EOF > "/etc/nginx/conf.d/nginx-${HOST}.conf"
+proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=sw360_cache:10m max_size=10g
+ inactive=60m use_temp_path=off;
+
upstream ${HOST}-app {
server ${HOST}:${HOST_PORT} max_fails=3;
}
@@ -69,6 +74,8 @@ server {
proxy_redirect off;
proxy_pass http://${HOST}-app;
proxy_read_timeout 3600s;
+
+ proxy_cache sw360_cache;
}
}
EOF
Whether this has a positive effect or whether this even leads to problems has to be checked.
Related Issue: https://github.com/sw360/sw360portal/issues/397 "Implement a Benchmark to messure Tomcat performance"
Client side caching can be enforced via
diff --git a/deployment/sw360nginx/docker-entrypoint.sh b/deployment/sw360nginx/docker-entrypoint.sh
index 0b51af5..c3856e3 100755
--- a/deployment/sw360nginx/docker-entrypoint.sh
+++ b/deployment/sw360nginx/docker-entrypoint.sh
@@ -35,6 +35,14 @@ fi
################################################################################
## generate /etc/nginx/conf.d/nginx-sw360.conf
cat <<EOF > "/etc/nginx/conf.d/nginx-${HOST}.conf"
+map \$sent_http_content_type \$expires {
+ default off;
+ text/html epoch;
+ text/css max;
+ application/javascript max;
+ ~image/ max;
+}
+
upstream ${HOST}-app {
server ${HOST}:${HOST_PORT} max_fails=3;
}
@@ -69,6 +77,8 @@ server {
proxy_redirect off;
proxy_pass http://${HOST}-app;
proxy_read_timeout 3600s;
+
+ expires \$expires;
}
}
EOF
the expires map did not work for me. as I tested the expires setting wth the dev tools browser. Have you tried it?
Another question would be for me to have the java scripts (and css) at max expiration for production. I suspect that updated css and Javascripts will not propagate then to the client?
OK, I see that the expiration does not count here, because the liferay requests use the timestamp syncing of the build time.
Question: did you observe improvements using the local proxy cache?
actually, I am not sure if the expires map proposal works, because eventually we found that the tomcat-served files are passed through at nginx and therefore the nginx needs to be configured as proxy rewrite.
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_hide_header expires;
proxy_redirect off;
proxy_pass http://liferay-app;
proxy_read_timeout 3600s;
proxy_set_header expires 7d;
}
Currently a lot of traffic is created when loading the sw360 pages. Some investigation reveals that a lot of small css other files are fetched by the browser.
In order to improve the responsiveness of the page browser caching could help. This feature needs to be configured at the nginx web server.
See eg https://www.digitalocean.com/community/tutorials/how-to-implement-browser-caching-with-nginx-s-header-module-on-centos-7
for details.