DEVOPS-1892: added cache settings

moved from angie to nginx
This commit is contained in:
Халтобин Евгений 2024-12-23 10:41:38 +03:00
parent 14976c6156
commit 497aa37497
4 changed files with 114 additions and 88 deletions

View file

@ -1,6 +1,6 @@
ARG BUILDER_IMAGE=registry.altlinux.org/basealt/altsp:c10f1
ARG BACKEND_IMAGE=repo.micord.ru/alt/alt-tomcat:c10f1-9.0.59-20240903
ARG FRONTEND_IMAGE=docker.angie.software/angie:latest
ARG FRONTEND_IMAGE=nginx:1.24-alpine-slim
FROM $BUILDER_IMAGE AS builder
@ -45,5 +45,5 @@ COPY --from=builder /app/frontend/target/frontend*.war /var/lib/tomcat/webapps/R
FROM $FRONTEND_IMAGE AS frontend
COPY config/angie.conf /etc/angie/angie.conf
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/frontend/dist /frontend

View file

@ -1,5 +1,5 @@
ARG BUILDER_IMAGE=registry.altlinux.org/basealt/altsp:c10f1
ARG RUNTIME_IMAGE=docker.angie.software/angie:latest
ARG RUNTIME_IMAGE=nginx:1.24-alpine-slim
FROM $BUILDER_IMAGE AS builder
@ -25,5 +25,5 @@ RUN mkdir -p $HOME/.m2 \
FROM $RUNTIME_IMAGE
COPY config/angie.conf /etc/angie/angie.conf
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/frontend/dist /frontend

View file

@ -1,84 +0,0 @@
include /etc/angie/modules-enabled.d/*.conf;
worker_processes 10;
error_log /var/log/angie/error.log;
events {
worker_connections 1024;
}
include /etc/angie/conf-enabled.d/*.conf;
http {
include /etc/angie/mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
# text/html doesn't need to be defined there, it's compressed always
gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml;
# gzip_comp_level 9;
include /etc/angie/sites-enabled.d/*.conf;
log_format angie_main
'$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$request_filename" "$gzip_ratio" $upstream_response_time server: $host : $document_root $fastcgi_script_name ';
server {
listen 80 default;
access_log /var/log/angie/access.log angie_main;
error_log /var/log/angie/error.log error;
charset utf-8;
client_max_body_size 32m;
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
location / {
root /frontend;
index index.html;
expires -1;
try_files $uri $uri/ $uri/index.html;
}
}
}

110
config/nginx.conf Normal file
View file

@ -0,0 +1,110 @@
include /etc/nginx/modules-enabled.d/*.conf;
worker_processes 10;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
include /etc/nginx/conf-enabled.d/*.conf;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
# text/html doesn't need to be defined there, it's compressed always
gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml;
# gzip_comp_level 9;
include /etc/nginx/sites-enabled.d/*.conf;
log_format nginx_main
'$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$request_filename" "$gzip_ratio" $upstream_response_time server: $host : $document_root $fastcgi_script_name ';
server {
listen 80 default;
access_log /var/log/nginx/access.log nginx_main;
error_log /var/log/nginx/error.log error;
charset utf-8;
client_max_body_size 32m;
##
# `gzip` Settings
#
#
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;
location / {
root /frontend;
index index.html;
try_files $uri @index;
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|ogg|ogv|webm|htc|woff2|woff|ttf)$ {
expires 1M;
access_log off;
# max-age must be in seconds
add_header Cache-Control "max-age=2629746, public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "max-age=31556952, public";
}
}
location @index {
root /frontend;
add_header Cache-Control no-cache;
expires 0;
try_files /index.html =404;
}
location = /health {
access_log off;
add_header 'Content-Type' 'application/json';
return 200 '{"status":"UP"}';
}
}
}