如何在nginx中禁用缓存?

时间:2015-08-07 09:14:00

标签: php nginx

我不熟悉nginx,无法编辑/修复通过nginx提供的php脚本。我的修复程序不可见 - 似乎脚本文件(或其输出)被缓存,可能是由nginx。配置文件不包含任何fastcgi_cache指令。

我需要更改什么才能编辑php脚本并查看其更新的输出?

php版本是5.4,因此它与opcache无关。它也不是与浏览器相关的,因为不同的浏览器,wget等也是如此。

nginx config:

user root users;
worker_processes  1;

#error_log  logs/error.log;
error_log  /var/log/nginx/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  off;
    proxy_buffering off;
    fastcgi_keep_conn on;

    #start server1 section
    server {
    listen       80;
    access_log  /var/log/nginx/access.log;
    location / {
        root   /var/www;
        index  index.php index.html index.htm;
    }

    location /db {
    proxy_pass        http://localhost:81/;
    }

    location /command {
    proxy_pass        http://localhost:82/;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    # php5-fpm
    location ~ \.php$ {
        root           /var/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_read_timeout 3600;
    }
    } #end server1 section

    #start server2 section [/db]
    server {
    listen       81;
    access_log  /var/log/nginx/db.log;
    location / {
        root   /var/www/db;
        index  index.php;
    }
    # php5-fpm
    location ~ \.php$ {
        root           /var/www/db;
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_read_timeout 3600;
    }
    } #end server2 section

    #start server3 section [/command]
    server {
    listen       82;
    access_log  /var/log/nginx/command.log;
    location / {
        root   /var/www/command;
        index  index.php;
    }
    # php5-fpm
    location ~ \.php$ {
        root           /var/www/command;
        fastcgi_pass   127.0.0.1:9002;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_read_timeout 3600;
    }
    } #end server2 section
}

fastcgi_params

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

更新

似乎缓存已经在fastcgi服务器中发生了。这是来自nginx错误日志(消息是伪造的,但确实表明php文件不是当前的):

2015/08/07 12:08:51 [error] 4050#0: *127 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'getID3' not found in /var/www/cover2.php on line 8" while reading response header from upstream, client: 192.168.0.66, server: , request: "GET /cover2.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.0.35"
2015/08/07 12:09:08 [error] 4050#0: *127 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'getID3' not found in /var/www/cover2.php on line 8" while reading response header from upstream, client: 192.168.0.66, server: , request: "GET /cover2.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.0.35"

2 个答案:

答案 0 :(得分:2)

织补。终于找到了罪魁祸首:

apc.stat = 0

这可以防止FastCGI PHP服务器中的IO检查。 opcache提示是线索,虽然它的APC,而不是opcache。

答案 1 :(得分:0)

它可能是一个浏览器对其经常访问的页面进行缓存,如果是这样,你可以试试这个:

编辑HTML元以告诉浏览器停止缓存:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

Source