Many people on the Internet say that when varnish and nginx are paired, varnish is in the front and nginx is in the back. Then I want to ask, if nginx is in the front, then nginx acts as a reverse proxy, then does varnish call fastcgi? The reason why I want to put varnish at the front is mainly to let varnish cache some static pages, pictures and other resources, and nginx is used to match fastcgi.
Question 2: In addition to caching static HTML, js, css, images and other resources, what else can Varnish cache? Dynamic pages should not be cached, right
Question 3: Experts, please come back. What is the difference between varnish first or nginx first?
PHP中文网2017-05-16 17:28:46
Such a structure doesn’t make much sense
1) Remove varnish and directly configure nginx as cache + fastcgi client (php-fpm behind is fastcgi server)
2) For load balancing, put two haproxy or lvs in front, heartbeat interconnection, and put a row of nginx behind
3) varnish Both nginx and nginx are html caches. Dynamic pages can also be cached. The html they generate is cached. The dynamic content in the page is cached through ajax. 4) For dynamic pages, more data-level caching is used, such as memcached and redis. 5) Varnish only does this. Regarding http caching, nginx integrates more protocols and can do more things, that's all.
过去多啦不再A梦2017-05-16 17:28:46
The website is not very popular, errors often appear, and no one cares about it
I wanted to reply before, but after typing, I found that I couldn't submit it. I don't know what happened.
Okay, now to answer your question. I have used the problem you mentioned in a production environment.
nginx is at the front and is responsible for diverting traffic: static resources are forwarded to varnish, and dynamic requests are forwarded to the php-fpm machine.
Whether dynamic pages need to be cached depends on business and performance requirements. It is possible to use varnish to cache specified dynamic pages.
过去多啦不再A梦2017-05-16 17:28:46
Nginx is placed in front of varnish for load balancing, and nginx is placed at the back to serve as a web server. Of course, varnish cannot be used as a web server to directly deal with PHP