首页 / 缓存 / 配置Nginx网页缓存时间!
配置Nginx网页缓存时间!
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了配置Nginx网页缓存时间!,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1967字,纯文字阅读大概需要3分钟。
内容图文
当 Nginx 将网页数据返回给客户端后,可设置缓存的时间,以方便在日后进行相同内容
的请求时直接返回,以避免重复请求,加快了访问速度,一般针对静态网页进行设置,对动
态网页不用设置缓存时间。可在 Windows 客户端中使用 fiddler 查看网页缓存时间。
设置方法:
在 可修改配置文件,在 http 段、或 server 段、或者 location 段加入对特定内容的过期参
数。
====================================================================
[root@localhost html]# vim /etc/nginx.conf
user nginx nginx;
worker_processes 2;
error_log logs/error.log;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
server_tokens off;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm;
}
location ~* \.(gif|jpg|jpeg|bmp|ico)$ { //如果是这种类型的文件缓存时间为一天
expires 1d;
}
location ~* \.(js|css)$ { //如果是js或css类型的文件缓存为一小时
expires 1h;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@localhost nginx-1.16.0]# cd
[root@localhost ~]# cd /usr/local/nginx/html/
导入图片
[root@localhost html]# rz
z waiting to receive.**B0100000023be50
[root@localhost html]# ls
50x.html index.html linux.jpg
[root@localhost html]# vim index.html
在尾部添加如下代码:
<p><em>Thank you for using nginx.</em></p> <img src='linux.jpg'/> </body> </html> ~
[root@localhost html]# killall -s HUP nginx //重启配置
内容总结
以上是互联网集市为您收集整理的配置Nginx网页缓存时间!全部内容,希望文章能够帮你解决配置Nginx网页缓存时间!所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。