Update nginx.conf with gzip configurations and server block for static file caching and serving

This commit is contained in:
Max Schmidt 2023-10-24 09:46:18 +02:00
parent 254cdcfda7
commit e062d42e66

View File

@ -1,6 +1,7 @@
events { events {
worker_connections 1024; worker_connections 1024;
} }
http { http {
gzip on; gzip on;
gzip_vary on; gzip_vary on;
@ -9,14 +10,19 @@ http {
gzip_buffers 16 8k; gzip_buffers 16 8k;
gzip_http_version 1.1; gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server { server {
listen 3000; listen 3000;
location ~* \.(jpg|jpeg|png|gif|ico|css|js|htm|html)$ {
expires 30d; # set long caching period on static files location / {
add_header Pragma public; root /usr/share/nginx/html;
add_header Cache-Control "public"; try_files $uri $uri/ =404;
try_files $uri $uri/ =404; # serve file if it exists, otherwise 404
} }
location ~* \.(jpg|jpeg|png|gif|ico|css|js|htm|html)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
} }
} }