Introduction to Nginx memcache cache

Source: Internet
Author: User
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.