2

我在 Ubuntu 12.04 上有 Nginx 1.4.1 和 PHP 5.5.7。Nginx 使用必要的附加功能进行编译。我已经设置了 fastcgi_cache 并安装了 Wordpress 作为测试站点。我也在使用 WP 的Nginx Helper 插件。我已经将配置精简到最基本的部分以尝试调试。fastcgi_cache 似乎正在工作,因为我创建了一个输出时间的 php 文件并从CURL 每次都显示相同的输出缓存位置也被文件填满,当我清除它时清空。

什么不起作用,我已经尝试了我能想到的所有配置,是“add_header X-Cache $upstream_cache_status;” 当添加到 nginx.conf 的 HTTP 块时,它应该添加“X-Cache = HIT 或 MISS,或 BYPASS 或其他东西。我根本无法显示它。我检查了其他服务器,我知道正在使用这个缓存并且标题确实出现了。我可以继续忽略它,但我想知道为什么有些东西不起作用,以防更多事情发生,以免它稍后回来咬我。

我想这可能是一个真正的错误,但我无法找到任何参考。这方面的信息很少,所以我求助于智囊团——有什么想法吗?配置文件如下。仅供参考,我尝试将 add_header 行放在服务器块和位置块中,以确保 - 不高兴。

example.com.vhost

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

add_header X-Cache $upstream_cache_status;

server {
    listen   80;
    server_name ~^(?:www\.)?(?P<example.com>.+)$ ;
    root /srv/www/$domain/htdocs;
    index index.php

    server_name example.com;


    location / {
        try_files $uri $uri/ /index.html;

    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_cache MYAPP;
        fastcgi_cache_valid 200 60m;
    }
}

nginx.conf

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;


    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
4

0 回答 0