This article mainly introduces about Nginx Memcache cache Introduction, has a certain reference value, now share to everyone, the need for friends can refer to
1 basic
In a LNMP architecture, Nginx encounters a dynamic resource, reverses the proxy, sends the request to the backend PHP-FPM service, PHP-FPM reads the data from MySQL, produces the page, and then returns to the client.
If the traffic is large, php-fpm and MySQL will become bottlenecks, and the solution is to add a memcached cache.
Nginx first put $uri as key, go to memcached to query value value, hit will directly return value to the client. If not, then pass the PHP-FPM. PHP-FPM returns the data to the client and stores a copy in the memcached.
So, this requires nginx and memcached connections, PHP and memcached connections.
2 PHP Installation memcache expansion module
PHP does not support the operation of the MEMCAHCE, need to install an interface.
Http://pecl.php.net/package/memcache Download memcache-2.2.7.tgz
Yum install M4 autoconf# installation dependent/app/php/bin/phpize# run Phpize, otherwise there is no Memcache file under Configure directory./configure--with-php-config =/app/php/bin/php-config# Installing the expansion module, using php-config make && make install# installation
When the installation is complete, memcache.so is generated.
Php/lib/php.ini file, there is a dynamic extension of the place, add memcache.so, restart php-fpm on the line
In info.php, you can verify the installation
3 Nginx Direct Connect memcache
Location/{ set $memcached _key "$uri"; Memcached_pass 127.0.0.1:11211; Error_page 404/callback.php; }
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!