2014-05-07 57 views
1

好了,我有这样我site.conf文件:如何缓存某些码页的nginx作为反向代理

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; 
} 
} 

利用这种配置,一切(包括POST请求方法)缓存为1分钟,好。

我需要什么?我需要的只是这个页面可以被缓存:

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) 

我的问题是:我必须把location /相匹配的1-5项?像这样:

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; 
} 

其他页面(未缓存)将被自动重定向到127.0.0.1:8080。我知道这可能是这样做:

location/{ 
    proxy_pass http://127.0.0.1:8080/; 
} 

注1:其他PHP页面接收POST | GET请求方法,但我并不需要它在高速缓存中,只有aboves。

注意:2127.0.0.1:8080是一个运行PHP的apache服务器,所以我可以请求PHP页面。

+1

此问题似乎属于Stack Exchange网络中的另一个站点,因为它不涉及编程。也许[超级用户](https://www.superuser.com/)或[服务器故障](http://serverfault.com/)。 – jww

回答

0

由于apache在同一主机上运行,​​只需提供您不想通过nginx缓存的html文件。至于PHP页面,请在您的应用程序中发送正确的过期标题,并且所有内容都将正常工作。

+0

不,我需要通过nginx提供缓存文件。问题是,我不知道如何修改位置/以匹配列表中的1-5项。注意:我编辑了我的问题(: – robe007