Answer the question
In order to leave comments, you need to log in
Why doesn't NGINX serve compressed files?
The NUXT SSR project generates gzip and brotli compressed files when built, but Chrome DevTools shows uncompressed files being transferred.
// nuxt.config.js
...
modules: [
[
"nuxt-compress",
{
gzip: {
cache: true
},
brotli: {
threshold: 10240
}
}
]
]
...
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
server_name mysite.com ;
charset UTF-8;
gzip on;
gzip_proxied any;
gzip_types text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json application/javascript;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
gzip_comp_level 8;
gzip_disable "msie6";
gzip_http_version 1.1;
brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml appl$
location / {
expires $expires;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://localhost:3001;
}
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name *.mysite.com;
return 301 https://mysite.com$request_uri;
listen 80;
return 404; # managed by Certbot
}
server {
if ($host = mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mysite.com;
listen 80;
return 404; # managed by Certbot
}
Answer the question
In order to leave comments, you need to log in
It turns out everything is working fine. Due to ESET antivirus, Chrome DevTools reflects false information, it is necessary to disable the antivirus and firewall.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question