[英]How to caching certains pages in nginx as a reverse proxy
Well, i have my site.conf file like this: 好吧,我有这样的site.conf文件:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_path /etc/nginx/cache/pag levels=1:2 keys_zone=APP:100m inactive=1m;
proxy_temp_path /etc/nginx/cache/tmp;
add_header X-Cache $upstream_cache_status;
server {
listen 80;
root /etc/nginx/html;
index index.html index.htm;
server_name www.example.com;
error_page 404 /404.html;
location /404.html {
internal;
}
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_cache APP;
proxy_cache_valid 200 1m;
proxy_cache_methods POST;
expires 1m;
}
}
With this configuration, everything (including POST request methods) is cached for 1 min, OK. 使用此配置,所有内容(包括POST请求方法)都将缓存1分钟,确定。
What i need? 我需要的? I need that only this pages can be cached:
我需要只能缓存以下页面:
1) www.example.com
2) www.example.com/index.html
3) www.example.com/test/page.html
4) www.example.com/test/text.txt (this is a file requested by POST thru page.html, and i need it cached also)
5) www.example.com/test/page2.php?var1=val1&var2=val2 (val1 and val2 are dynamics)
My question is: What i have to put in location /
to match the 1-5 items? 我的问题是:我必须放置什么
location /
才能匹配1-5个项目? Like this: 像这样:
location (1-5 items match) {
proxy_pass http://127.0.0.1:8080/;
proxy_cache APP;
proxy_cache_valid 200 1m;
proxy_cache_methods POST;
expires 1m;
}
Other pages (not cached) will be automatically redirected to 127.0.0.1:8080. 其他页面(未缓存)将自动重定向到127.0.0.1:8080。 I know this can be do like this:
我知道可以这样做:
location / {
proxy_pass http://127.0.0.1:8080/;
}
NOTE 1: Other PHP pages receive POST|GET request methods, but i don't need it in cache, only aboves. 注1:其他PHP页面接收POST | GET请求方法,但仅在上述情况下,我不需要在高速缓存中使用它。
NOTE: 2 127.0.0.1:8080
is an apache server that runs PHP, so i can request PHP pages. 注意:2
127.0.0.1:8080
是运行PHP的Apache服务器,因此我可以请求PHP页面。
Since apache runs on the same host, simply serve the html files you do not want cached through nginx. 由于apache在同一主机上运行,因此只需提供您不想通过nginx缓存的html文件。 As for the php pages, send the correct expiration headers in your application and everything will work correctly.
至于php页面,请在您的应用程序中发送正确的到期标头,然后一切都会正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.