我已将 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;
}
}
}