配置Nginx网页缓存时间!

当 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]# rzz waiting to receive.**B0100000023be50[root@localhost html]# ls50x.html index.html linux.jpg

[root@localhost html]# vim index.html

在尾部添加如下代码:

Thank you for using nginx.

~

[root@localhost html]# killall -s HUP nginx //重启配置

QQ飞车为什么服务器进不去,进不去游戏怎么解决
台上讲暴富,台下背负债,那些忽悠人的“成功学大师”都有谁
Copyright © 2022 全球游戏最新活动中心 All Rights Reserved.