Answer the question
In order to leave comments, you need to log in
How to properly organize caching on Nginx + NodeJS?
Site on NodeJs. Nginx redirects requests to the port that NodeJs listens on - everything is simple, but probably because of this, caching cannot be enabled. Missed something.
Followed this article to configure file caching on the server. As a result, nothing is cached. Also followed these tips - did not help. After each change I restart nginx sudo systemctl restart nginx
Where is the error and how to enable caching?
Site config file:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://IP_ADDRESS:PORT;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
/home/example.com/public/dist
/home/example.com/public
app.use(express.static(__dirname + '/../public', { maxAge: '30 days' }));
Answer the question
In order to leave comments, you need to log in
Add a location /public
without proxying, but with an indication of the directory where the files are located. If the node will also give them - just add the appropriate headers to the location - Cache-Control
and so on.
location /public {
root /home/example.com/public/;
add_header Cache-Control "private, max-age=86400";
}
location / {
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question