nginx cache and error page configuration
- 2020-05-12 06:55:10
- OfStack
Native cache Settings
Browser caching is used to speed up loading, so we can cache static files via Nginx.
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
# overdue 30 day
expires 30d;
}
Define the error page
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
Automatic display directory
location / {
autoindex on;
}
In addition, you can add two parameters
autoindex_exact_size off; The default is on, which shows the exact size of the file in bytes. When changed to off, the approximate size of the file is displayed in kB or MB or GB units
autoindex_localtime on; The default is off, and the time of the file displayed is GMT time. After changing to on, the time of the file displayed is the server time of the file
The above is the site to introduce you nginx cache and error page configuration, I hope to help you, if you have any questions please give me a message, this site will be timely
Here's what others have to add
Nginx cache, compression configuration
1. Cache configuration
Only need to be configured in http's server module, such as:
location ~.*\.(jpg|png|gif)$ {
expires d 30;
}
location ~.*\.(css|js)?${
1 h expires;
}
2. Compression configuration
gzip on
1 k gzip_min_length; Over 1K before compression
16 k gzip_buffers 4; Set the memory
gzip_http_version 1.1; http agreement
3. Automatically change the directory
autoindex on;
Reply to everyone. Here also thank you very much for your support of this site!