Varnish,nginx Building a cache server
I. Varnish1. Install the Pcre library, compatible with regular expressions# TAR-ZXVF Pcre-8.10.tar.gz# CD pcre-8.10#./configure--prefix=/usr/local/pcre# Make && make install2. Configuring the Installation Varnish# TAR-ZXVF Varnish-3.0.2.tar.gz# CD varnish-3.0.2# Export pkg_config_path=/usr/local/pcre/lib/pkgconfig/#./configure--prefix=/usr/local/varnish# Make && make install3. Modify the varnish configuration file/usr/Local/varnish/etc/varnish/default.vcl# MV DEFAULT.VCL Default.vcl.bak# vi Cq.vclbackend cqserver {. host ="127.0.0.1";. Port ="8087";. Connect_timeout =20s;} ACL Purge {"LocalHost";"127.0.0.1";"192.168.1.0"/24;}SubVcl_recv{if (req.request = ="PURGE") {if (!client.ip ~ purge) {Error405"Not allowed.";}return (lookup);}if (req.http.host ~"^www.baidu.com") {set req.backend = Cqserver;if (req.request! ="GET" && req.request! ="HEAD") {Return (pipe);}else{return (lookup);}}else {error404"Caoqing Cache Server";return (lookup);}}SubVcl_hit{if (req.request = ="PURGE") {Set Obj.ttl = 0s;error200"Purged.";}}SubVcl_miss{if (req.request = ="PURGE") {Error404"Not in cache.";}} (1) varnish through the reverse proxy request back-end IP127.0.0.1, the port is8087 Web server, which is the Nginx server listening port;2) varnish allows localhost,127.0.0.1.192.168.1.* three source IP clears the cache through the Purge method;3) Varnish requests for domain name www.baidu.com are processed, and non-www.baidu.com domain name requests are returned"Caoqing Cache Server"; (4) Varnish The Get and head requests in the HTTP protocol, and through the POST request, it accesses the backend Web server directly.4. Start varnish# cd/usr/local/varnish/sbin/#./varnishd-f/usr/local/varnish/etc/varnish/cq.vcl-s file,/var/varnish_cache,1g-t 127.0.0.1:2000-a 0.0.0.0:80 two. Nginx1. Installing Nginx# RPM-IVH zlib-devel-1.2.3-4.el5.i386.rpm# tar ZXVF nginx-1.4.1.tar.gz# CD nginx-1.4.1#./configure--prefix=/usr/local/nginx--with-openssl=/usr/lib--with-pcre=/root/tool/pcre-8.10--with-http_stub_ Status_module# Make && make install2. Start Nginx# Cd/usr/local/nginx/sbin#./nginx3. Modify the Ngnix Profile test configuration file/usr/Local/nginx/sbin/./nginx-t# cd/usr/local/nginx/conf# VI Nginx.conf#使用的用户和组user root root;#制定工作衍生进程数 (typically twice times the total CPU count) worker_processes8;#制定文件描述符数量worker_rlimit_nofile51200;#指定错误日志存放路径error_log Logs/error.log#指定pid存放路径pid logs/nginx.pid;event{#使用网络I/O ModelUse Epoll;#允许的连接数 worker_connections65535;} HTTP {#访问日志存放路径 Access_log Logs/access.log;#开启gzip压缩 gzip on; Gzip_min_length1000; Gzip_proxied ExpiredNo-cacheNo-store Private auth; Gzip_types text/plain text/css text/xml text/javascript application/X-javascript application/xml application/rss+xml application/xhtml+xml application/atom_xml; Gzip_disable"MSIE [1-6]. (?!. *SV1) ";#限定PHP-cgi Connection, transmit, and read time is 300s Fastcgi_connect_timeout300S Fastcgi_send_timeout300S Fastcgi_read_timeout300S#虚拟主机配置server {#监听端口Listen8087;#主机名称 server_name127.0.0.1;#google提供的DNS服务 Resolver8.8.8.8 Location/{#nginx作为HTTP代理服务器 Proxy_pass http:$http _host$request_uri; Proxy_set_header accept-encoding‘‘; Proxy_redirect off; }}} three. Troubleshooting optimization1) Modify the environment variable VI ~/.bashrcpath= $PATH:/usr/local/nginx/sbin:/usr/local/varnish/sbin:/usr/local/varnish/ BINEXPORT PATH2) Nginx Startup and shutdown parameters:-V: View version-V: View Configuration Module-T: To see if the configuration file is correct-C: Make additional configuration Files pkill -9 nginx3) Varnish startup and Shutdown parameters: -u: What user runs the-G: In what group to run the-f:varnish profile -a: Bind IP and Port-s:varnish cache location and Size-W: Minimum, Maximum thread and timeout time-t:varnish management port, mainly used to clear the cache Pkill varnishdvarnish service dynamically load profiles #varnishadm -T 127.0.0.1:2000vcl.load vcl-name_vcl "Profile path" # vcl-name here can be any name vcl.use vcl-namevcl.show vcl-name #显示vcl-name configuration file Contents # varnishncsa -w /usr /local/varnish/logs/varnish.log writes output logs to the development log file. 4) modify Windows client C:\windows\system32\drivers\etc\hosts 192.168.1.202 www.baidu.com
Source: Https://my.oschina.net/u/1449160/blog /198650
Varnish,nginx building a cache server