适用于Magento的Nginx PHP-FPM FastCGI缓存配置

前端之家收集整理的这篇文章主要介绍了适用于Magento的Nginx PHP-FPM FastCGI缓存配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

你们中的一些人可能已经注意到几天前Magento发布的最近的Optimizing Magento For Peak Performance白皮书.虽然它主要是为EE用户编写的,但我相信我们也可以使用社区版的大部分技巧.

读完后,我继续将他们建议的Nginx fastcgi /代理缓存配置与Magento的标准虚拟主机配置合并,并进行了一些小的改进.这是我想出的:

fastcgi_cache_path /tmp/fcgi levels=1:2 keys_zone=MAGE:64m max_size=128m inactive=10h;

server {
listen  99999; ## Nginx port
server_name  domain.com www.domain.com;
root  /www/magento; ## App folder
index  index.PHP;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)${
    expires  max;
    access_log  off;
    log_not_found  off;
}

location /index {
    try_files  $uri @fcgi_nocache;
}

location /checkout {
    try_files  $uri @fcgi_nocache;
}

location / {
    try_files  $uri @fcgi_cache;
    if ($cookie_frontend) { return 413; }
    if ($cookie_CUSTOMER_AUTH) { return 413; }
    if ($request_method = POST ) { return 413; }
    error_page 413 = @fcgi_nocache;
}

# Deny access to hidden files
location ~ (/(app/|includes/|/pkginfo/|var/|report/config.xml)|/\.svn/|/.hta.+) {
    deny  all;
}

# Forward paths like /js/index.PHP/x.js to relevant handler
location ~ .PHP/ {
    rewrite ^(.*.PHP)/ $1 last;
}

# Manually purge pages
location ~ /purge(/.*) {
    fastcgi_cache_purge MAGE "$scheme$request_method$host$1";
}

location @fcgi_cache {
    #if (!-e $request_filename) { rewrite / /index.PHP last; } ## Catch 404s that try_files miss
    fastcgi_pass  unix:/var/spool/PHPfpm.sock; ## PHP-fpm socket
    include  fastcgi_params;
    fastcgi_connect_timeout  60;
    fastcgi_send_timeout  60;
    fastcgi_read_timeout  60;
    fastcgi_buffer_size  4k;
    fastcgi_buffers  512 4k;
    fastcgi_busy_buffers_size  8k;
    fastcgi_temp_file_write_size  256k;
    fastcgi_intercept_errors  off;        
    fastcgi_param SCRIPT_FILENAME  $document_root/index.PHP;
    fastcgi_param SCRIPT_NAME  /index.PHP;
    #fastcgi_keep_conn  on; # Nginx 1.1.14        
    fastcgi_temp_path  /tmp/fcgi2 1 2;

    fastcgi_cache  MAGE;
    #fastcgi_cache_key  "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri"; ## Original
    fastcgi_cache_key  "$scheme$request_method$host$request_uri$http_if_modified_since$http_if_none_match";
    #fastcgi_cache_lock  on 5s; # Nginx 1.1.12
    fastcgi_cache_valid  200 301 302 304 1h;
    fastcgi_hide_header  "Set-Cookie";

    if ($http_cookie !~ "X-Store=1" ) {
        add_header Set-Cookie "X-Store=1; path=/";
    }

    fastcgi_ignore_headers  "Cache-Control" "Expires" "Set-Cookie";
    fastcgi_cache_min_uses  1;
    fastcgi_cache_valid  30m;
    fastcgi_cache_use_stale  updating error timeout invalid_header http_500;
    fastcgi_cache_bypass  $cookie_EXTERNAL_NO_CACHE $cookie_CUSTOMER_AUTH;
    fastcgi_no_cache  $cookie_EXTERNAL_NO_CACHE $cookie_CUSTOMER_AUTH;

    #add_header  X-Cache-Status $upstream_cache_status; # Test
}

location @fcgi_nocache {
    #if (!-e $request_filename) { rewrite / /index.PHP last; } ## Catch 404s that try_files miss
    fastcgi_pass  unix:/var/spool/PHPfpm.sock; ## PHP-fpm socket
    include  fastcgi_params;
    fastcgi_connect_timeout  60;
    fastcgi_send_timeout  60;
    fastcgi_read_timeout  60;
    fastcgi_buffer_size  4k;
    fastcgi_buffers  512 4k;
    fastcgi_busy_buffers_size  8k;
    fastcgi_temp_file_write_size  256k;
    fastcgi_intercept_errors  off;        
    fastcgi_param SCRIPT_FILENAME  $document_root/index.PHP;
    fastcgi_param SCRIPT_NAME  /index.PHP;
    #fastcgi_keep_conn  on; # Nginx 1.1.14        
    fastcgi_temp_path  /tmp/fcgi2 1 2;

    if ($http_cookie !~ "X-Store=1" ) {
        add_header Set-Cookie "X-Store=1; path=/";
    }
    #add_header  X-Cache-Status $upstream_cache_status; # Test
}

}

经过一些测试后,结果看起来令人印象深刻,但是如果它们是准确的并且缓存系统是否按预期完全正常工作,我真的不自信.有人可以详细说明@fcgi_cache和@fcgi_nocache以及cookie背后的实际逻辑是什么?谁实际上获得了缓存页面?当PHP-FPM关闭(?)时,过时的缓存似乎不起作用.我有点被困,并且对我得到的不同标题有点困惑.

建议谁?

最佳答案
这种类型的配置对magento来说绝对没用,他们只使用它来获得最大的“虚拟”吞吐量,而且这个配置逻辑甚至会在很少的地方中断.
您最好配置打孔整页缓存扩展,它将重新插入您的动态块,并将您的站点始终保持在缓存中.对于新添加的产品和数量变化等,必须有缓存刷新.
原文链接:https://www.f2er.com/nginx/434469.html

猜你在找的Nginx相关文章