2011-10-14 67 views
1

我正在寻找一种解决方案来在网络服务器上长期(几天/几周)缓存404s。我目前的设置是使用memcached_pa​​ss代理和PHP-FPM提供未缓存页面的NGINX(PHP也将内容写入memcached)。 网络上的爬虫似乎喜欢我的页面,并且每天生成几千个404请求。他们都直接命中PHP,因为我无法将404响应头信息与memcached中的内容一起缓存,因此memcached_pa​​ss查找总是失败。缓存404s - NGINX或涂有?

如何缓存所有返回404的请求? Nginx的HTTPProxModule是我在找什么?还是我应该去清漆?

从我当前的观点来看,我并不热衷于更改我的整个设置并从nginx中删除memcached_pa​​ss指令。到目前为止,它非常整齐,因为php决定请求是否可以(应该)缓存在memcached中。在必要时刷新缓存也很容易。

我现在NGINX配置文件:

server { 
    listen  80; 
      server_name _; 


      gzip on; 
      gzip_http_version 1.0; 
      gzip_vary on; 
      gzip_comp_level 6; 
      gzip_proxied any; 
      gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    location/{ 
        gzip on; 
     default_type "text/html; charset=utf-8"; 
        charset   utf-8; 
        add_header Content-Encoding gzip; 

     if ($request_method = GET) 
     { 
       expires  max; 
       set $memcached_key $http_host$request_uri; 
       memcached_pass  127.0.0.1:11211; 
       error_page   404 = @fallback; 
       #error_page 502 = @fallback; 
       break; 
     } 

     root /var/www/html/; 
     index index.php index.html; 

     if (!-e $request_filename) { 
      rewrite ^/(.*)$ /index.php?q=$1 last; 
      break; 
     } 

    } 



    location @fallback { 
        internal; 
     root /var/www/html/; 
     index index.php index.html; 

     if (!-e $request_filename) { 
      rewrite ^/(.*)$ /index.php?q=$1 last; 
      break; 
     } 


    } 

    location ~ \.php$ { 
     root /var/www/html/; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; 
       include /etc/nginx/fastcgi_params; 
    } 


} 

一个例子配置无论是Nginx的或清漆将是巨大的。

谢谢! :)

回答