2013-02-17 46 views
0

我有nginx的設置爲提供HTML內容直接從memcached的,但用我們自己的後端(而不是傳統的設立因而故障切換到PHP配置),但是無論何時在PHP中設置頁面以便從memcached中檢索,nginx似乎都可以找到它,但只需下載一個名爲「download」的文件,其內部看起來像是二進制數據。nginx的memcached的和,返回「下載」作爲附件,而不是HTML內容

這是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; 
     } 

    } 

} 
+0

這個問題可能是[ServerFault(http://serverfault.com)更好。投票遷移。 – 2013-02-17 21:16:34

回答

0

的根本原因那就是德memcached的結果不具有自動關聯MIME類型,這意味着它們會擔任默認二進制。

要修復它下面的指令添加到您的@memcached位置:

default_type text/html; 
+0

嗨,這工作,好吧,它停止了作爲下載來通過,但現在的內容是這樣返回 xœí=iwÛF'Ÿíòò:ô¼H$ $À''y',ÇžøPl9žl'§×$ 「@ PB <þ5ûOö-mUwh ACEO»™A「ú¨®®®ª®ª¾ž|ýôÍéÅOçgd」 OE =rþþäå ¸O½FãìuÔFIî7「 ɤ>iÕƒhظxÛ¸AXV - ?μD©ÿ·»VOD \toðfìùñac0Ú5,'ïQxXc〜¿XA} CIEA°>˚F n8æ#Þ£6üùZÓ〜VA%äÅéý )C-P,μ4ö{E 1 OTH¥½ÖNƒqH×ôXXŸ0???? 9¬½8; <³‡lÏEÁ~÷EY™ö»Î¯šžë_'y‡μ8™Z,1-OE(bÎaa²$a'I¨Œã/ R·AOׇz¯FÆÌvéazÐÑÆA\ÉÐLê'YÒP2 UA -a7IÀf KSA \t OCJ×GD [AF8 = I€5ÕoD°ÖX³ÉÆoôšÆVä†I#Ó (\téÐõiD3Ÿ:iÌÌà×uœ%®Ë - ã5ê 任何建議爲什麼? – glambert 2013-02-18 09:36:01

+0

看起來像memcached項目zlib壓縮在PHP中,我最好喜歡保持它的方式,但有沒有辦法通過nginx解壓? – glambert 2013-02-18 11:05:48

+0

我不認爲你需要:瀏覽器的根解壓縮gzip壓縮HTML,但是你需要通過添加'add_header內容編碼gzip的信號是,'你的memcached的指令 – cobaco 2013-02-18 11:31:38

相關問題