0

我已将 nginx 设置为直接从 memcached 提供 html 内容,但使用我们自己的后端(不是传统设置因此配置)故障转移到 PHP,但是每当在 PHP 中设置要从 memcached 检索的页面时,就会出现 nginx找到它,然后只需下载一个名为“下载”的文件,其中包含看起来像二进制数据的文件。

这是 nginx.conf 文件,它是使用增强型 memcached 模块从源代码构建的。

worker_processes  1;

events {
    worker_connections  1024;
}

http {

    include /usr/local/nginx/conf/mime.types;
    default_type application/octet-stream;

    server {
        listen 80;
        server_name localhost;
        location / {
                root /var/www;
                index index.html;
        }
        location ~* \.php$ {
                root /var/www;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                include fastcgi_params;
        }
    }

    server {
        listen 80;
        server_name mydomain.com;
        access_log /path/to/access/log/access_log;
        error_log /path/to/error/log/error_log;
        root /u1/live/sites/public_html;

        location ~* \.(jpg|png|gif|css|js|swf|flv|ico|html|woff|ttf|svg|htm)$ {
                try_files $uri $uri/ $uri.html @notcached;
        }

        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 240;
                include fastcgi_params;
        }

        location / {
                set $enhanced_memcached_key "$server_name$request_uri";
                enhanced_memcached_hash_keys_with_md5 on;
                enhanced_memcached_pass memcache.local:11211;
                error_page 404 = @notcached;
        }

        location @memcache {
                set $enhanced_memcached_key "$server_name$request_uri";
                enhanced_memcached_hash_keys_with_md5 on;
                enhanced_memcached_pass memcache.local:11211;
                error_page 404 = @notcached;
        }

        location @notcached {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME /path/to/main/php/file/index.html;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_read_timeout 240;
                include fastcgi_params;
        }

    }

}
4

1 回答 1

0

其根本原因是 memcached 结果没有自动关联的 mimetype,这意味着它们默认以二进制形式提供。

要修复它,请将以下指令添加到您的 @memcached 位置:

default_type text/html;
于 2013-02-17T21:21:13.587 回答