Optimise nginx configuration and enable dynamic compression

This commit is contained in:
Fred Boniface 2024-04-19 21:17:16 +01:00
parent 958eabe76e
commit 735853aa8d
1 changed files with 17 additions and 7 deletions

View File

@ -1,4 +1,5 @@
load_module modules/ngx_http_brotli_static_module.so; load_module modules/ngx_http_brotli_static_module.so;
load_module modules/ngx_http_brotli_filter_module.so;
user nginx; user nginx;
worker_processes auto; worker_processes auto;
@ -20,7 +21,7 @@ http {
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; access_log /dev/stdout main;
sendfile on; sendfile on;
@ -51,25 +52,34 @@ http {
location / { location / {
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index; index /index.html;
gzip_static on; gzip_static on;
brotli_static on; brotli_static on;
error_page 500 502 503 504 /err/50x.html; error_page 500 502 503 504 /err/50x.html;
error_page 404 /err/404; try_files $uri $uri/ /index.html;
try_files $uri.html $uri $uri/index.html $uri/ =404;
add_header Cache-Control "public, no-transform, max-age=1209600"; add_header Cache-Control "public, no-transform, max-age=1209600";
if ($uri ~* \.html$) { rewrite ^([^.]*[^/])$ $1/ permanent;
return 404;
}
} }
location /misc/ { location /misc/ {
proxy_pass http://backend; proxy_pass http://backend;
brotli on;
brotli_comp_level 6;
brotli_types *;
gzip on;
gzip_comp_level 6;
gzip_types *;
} }
location /api/ { location /api/ {
proxy_pass http://backend; proxy_pass http://backend;
brotli on;
brotli_comp_level 6;
brotli_types *;
gzip on;
gzip_comp_level 6;
gzip_types *;
proxy_cache_key $scheme://$host$uri$is_args$query_string; proxy_cache_key $scheme://$host$uri$is_args$query_string;
proxy_ignore_headers Cache-Control; proxy_ignore_headers Cache-Control;
proxy_cache_valid 200 2m; # Evaluate whether 2m or 1m is more appropriate proxy_cache_valid 200 2m; # Evaluate whether 2m or 1m is more appropriate