找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: t9913085

请教一下下面这个nginx反代缓存静态文件有问题吗

[复制链接]

56

主题

866

回帖

1942

积分

金牌会员

积分
1942
发表于 2017-12-24 15:38:03 | 显示全部楼层
嘛,location 这玩意,满头雾水很正常,以下仅做参考:

server {
        listen 80;

        server_name 你的域名;

        location / {
                   proxy_pass http://163.172.XXX.XXX:80;
                   proxy_redirect off;
                   proxy_set_header Host  "163.172.XXX.XXX:80";
                   proxy_set_header X-Real-IP  $remote_addr;
                   proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
                   proxy_pass http://163.172.XXX.XXX:80;
                   proxy_redirect off;
                   proxy_set_header Host  "163.172.XXX.XXX:80";
                   proxy_set_header X-Real-IP  $remote_addr;
                   proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;

                   proxy_cache的相关设置这里我没写出来,根据我那篇文章,按你需求自行配置,server 段的部分写在这里
        }
}


看了上面,你会发现我在两个 location 中写了相同的反代配置。这样就能避免前面我提到的问题。

关于 proxy_cache 的相关设置,一楼那个模板你全部丢掉就行,不知道你找的多少个网站复制夹杂的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Discuz! X

GMT+8, 2025-4-21 05:42 , Processed in 0.014018 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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