小编And*_*Sun的帖子

Nginx 忽略用于缓存某些文件的查询字符串

我知道我的设置有点疯狂,但无论如何......

我在 Openshift 上设置了 Nginx 来缓存地图图块(对于地图查看器,您可以猜到目的,:-)),这些图块由我的家庭网络提供,该网络带宽有限(愚蠢的无线连接!)。Openshift 为我提供了无限带宽和 1 GB 磁盘,这应该足以缓存地图的热门部分。

但是,地图查看器喜欢发出这样的请求:

http://localhost/tiles/world/t/-1_0/-27_23.png?1381358434308
Run Code Online (Sandbox Code Playgroud)

这让 nginx 认为该文件不可缓存!我已经做了一些谷歌搜索,但由于我在阅读和编写正则表达式方面很糟糕,我想(从你那里)请求一种方法让 nginx 忽略 .png 文件的查询字符串,并且只从缓存中提供版本而不需要请求参数。

以下是服务器配置的相关部分:

http {

  proxy_cache_path  ${OPENSHIFT_RUNTIME_DIR}/cachefile levels=1:2 keys_zone=my-cache:599m max_size=700m inactive=250m;
  proxy_temp_path ${OPENSHIFT_RUNTIME_DIR}/cachefile/tmp; 
    include mime.types;
    default_type application/octet-stream;

    # Format for our log files
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '
      '"$request" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile on;
    keepalive_timeout 5;
    access_log ${OPENSHIFT_LOG_DIR}/access.log;

    port_in_redirect off;
    server_tokens off;

    tcp_nopush on; # off may be better for Comet/long-poll stuff
    tcp_nodelay off; # on may be …
Run Code Online (Sandbox Code Playgroud)

nginx cache reverse-proxy querystring

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

cache ×1

nginx ×1

querystring ×1

reverse-proxy ×1