VPS侦探论坛

 找回密码
 注册
查看: 3162|回复: 5

请教下,如何反代缓存全部文件?

[复制链接]
发表于 2017-11-20 15:15:39 | 显示全部楼层 |阅读模式

因为伪静态导致CPU 一直100%现在想用反代,把全部页面都缓存成静态的
请教下该怎么修改conf才能把html,js和图片都缓存下来呢
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2017-11-20 18:36:46 | 显示全部楼层


https://www.vpser.net/manage/linux-vps-nginx-reverse-proxy.html
再加上
proxy_cache fandai_cache;
proxy_cache_key %s$request_uri$is_args$args;
proxy_cache_valid 200 304 301 302 1h;
上面缓存时间1h可以自己调整一下
nginx.conf 里或者server段前加上
proxy_cache_path  /home/fandai_cache  levels=1:2   keys_zone=fandai_cache:10m max_size=10g;
proxy_cache_key  "$host$request_uri";
目录都提前创建好
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2017-12-3 22:50:11 | 显示全部楼层

回复 2# 的帖子


请教下军哥,是按下面这样吗?html和js如何指定保存?
我在home下新建了fandai_cache文件夹了,然后修改了 /usr/local/nginx/conf/vhost 对应的网站conf文件
proxy_cache_path  /home/fandai_cache  levels=1:2   keys_zone=fandai_cache:10m max_size=10g;
proxy_cache_key  "$host$request_uri";
server
        {
            listen          80;
            server_name     www.kwxonline.com;

            location / {
        proxy_pass          http://www.kwx.gd/;
        proxy_redirect      off;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache fandai_cache;
        proxy_cache_key %s$request_uri$is_args$args;
        proxy_cache_valid 200 304 301 302 24h;
        }
}
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2017-12-3 22:51:10 | 显示全部楼层

回复 2# 的帖子




请教下军哥,是按下面这样吗?html和js如何指定保存?
我在home下新建了fandai_cache文件夹了,然后修改了 /usr/local/nginx/conf/vhost 对应的网站conf文件
proxy_cache_path  /home/fandai_cache  levels=1:2   keys_zone=fandai_cache:10m max_size=10g;
proxy_cache_key  "$host$request_uri";
server
        {
            listen          80;
            server_name     www.kwxonline.com;

            location / {
        proxy_pass          http://www.kwx.gd/;
        proxy_redirect      off;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache fandai_cache;
        proxy_cache_key %s$request_uri$is_args$args;
        proxy_cache_valid 200 304 301 302 24h;
        }
}
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2017-12-4 13:05:53 | 显示全部楼层

添加上个location
  1.         location ~ .*\.(html|js)$
  2.         {
  3.             proxy_cache fandai_cache;
  4.             proxy_cache_key %s$request_uri$is_args$args;
  5.             proxy_cache_valid 200 304 301 302 1h;
  6.         }
复制代码

试试

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2017-12-4 14:48:37 | 显示全部楼层

回复 5# 的帖子


额,这代码加哪没看懂了,能完整的写一下吗。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-24 23:22 , Processed in 0.030781 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表