Nginx+Varnish+基本业务

ngnix nginx.conf配置文件

user  root;
worker_processes ; error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info; pid logs/nginx.pid; events {
use epoll;
worker_connections ;
} http {
include mime.types;
include ccproxy.conf;
default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; server_names_hash_bucket_size ;
client_body_buffer_size 128k;
client_header_buffer_size 8k;
client_max_body_size 50m;
client_header_timeout 1m;
client_body_timeout 1m;
large_client_header_buffers 8k; send_timeout 3m; sendfile on;
tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ;
tcp_nodelay on; gzip on;
gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.1;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on; upstream cctest1.com {
server 127.0.0.1: weight=;
server 127.0.0.1: weight=;
} upstream cctest2.com {
server 127.0.0.1:;
} server {
listen ;
server_name ccserver1; #charset koi8-r; access_log logs/host.access.log main; index index.html index.htm index.jsp;
root /usr/common/apache-tomcat-7.0.78_1/webapps/ROOT/; #location ~* ^/arch1/.*\.(jpg|jpeg|gif|png|swf|ico)$ {
# root /usr/common/apache-tomcat-7.0.78_1/webapps;
#} #location ~* ^/arch1/.*\.(html|htm|js|css)$ {
# root /usr/common/apache-tomcat-7.0.78_1/webapps;
#} #location ~* .*\.(jpg|jpeg|gif|png|swf|ico)$ {
# if (-f $request_filename) {
# #expires 15d;
# break;
# }
#} #location ~* .*\.(html|htm|js|css)$ {
# if (-f $request_filename) {
# #expires 1d;
# }
#} #location / {
# proxy_pass http://cctest1.com; #} location / {
proxy_pass http://cctest2.com; } #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
internal;
root errors/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

varnish default.vcl文件

# This is a basic VCL configuration file for varnish.  See the vcl()
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
# import std; backend b1 {
.host = "127.0.0.1";
.port = "";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
.max_connections=;
.probe = { .url = "/index.jsp";
.timeout = 0.3 s;
.window = ; //要检查后端服务器的次数
.threshold = ; //.window里面要有多少polls成功就认为后端是健康的
.initial = ; //当varnish启动的时候,要确保多少个probe正常
} } backend b2 {
.host = "127.0.0.1";
.port = "";
.connect_timeout = 1s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 2s;
.max_connections=;
.probe = { .url = "/index.jsp";
.timeout = 0.3 s;
.window = ; //要检查后端服务器的次数
.threshold = ; //.window里面要有多少polls成功就认为后端是健康的
.initial = ; //当varnish启动的时候,要确保多少个probe正常
} } director d1 round-robin { {
.backend = b1;//引用已经存在的backend } {
.backend = b2; }
} acl purgeallow {
"127.0.0.1";
} sub vcl_recv { set req.backend = d1;
set req.grace =50s;
if (! req.backend.healthy) {
set req.grace = 5m;
} else {
set req.grace = 15s;
} if(req.request =="PURGE") {
if(!client.ip ~ purgeallow){
error "not allowed";
}
return(lookup);
} if(req.request =="GET" && req.url ~ "\.(css|htm|html|js|jpg|png|gif|swf|flv|ico|jpeg)$"){
unset req.http.cookie;
} if (req.restarts == ) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
} if( req.request =="GET" && ((req.url ~ "(?i).*/toLogin")||(req.url ~ "(?i).*/toIndex")||(req.url ~ "(?i).*/toGoodsDesc/.*"))){
return (lookup);
} if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
#
sub vcl_pipe {
# # Note that only the first request to the backend will have
# # X-Forwarded-For set. If you use X-Forwarded-For and want to
# # have it set for all requests, make sure to have:
# # set bereq.http.connection = "close";
# # here. It is not set by default as it might break some broken web
# # applications, like IIS with NTLM authentication.
return (pipe);
}
#
sub vcl_pass {
return (pass);
}
#
sub vcl_hash { hash_data(req.url);
std.log("url hash! the url=" + req.url); #if (req.http.host) {
# hash_data(req.http.host);
#} else {
# hash_data(server.ip);
#}
return (hash);
}
#
sub vcl_hit {
return (deliver);
}
#
sub vcl_miss {
return (fetch);
}
#
sub vcl_fetch { set beresp.grace=30m; if(req.request =="GET" && req.url ~ "\.(css|html|htm|js|jpg|png|gif|swf|flv|ico|jpeg)$"){
set beresp.ttl =1d;
} if(req.url ~ "(?i).*/toIndex"){
set beresp.ttl =3m;
return(deliver);
} if((req.url ~ "(?i).*/toGoodsDesc/.*")||(req.url ~ "(?i).*/toLogin")){
set beresp.ttl =2h;
return(deliver);
} if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
# /*
# * Mark as "Hit-For-Pass" for the next 2 minutes
# */
set beresp.ttl = s;
return (hit_for_pass);
} if( beresp.http.Pragma ~ "no-cache" ||
beresp.http.Cache-Control ~ "no-cache" ||
beresp.http.Cache-Control ~ "private" ){
return(deliver);
} if(beresp.status == || beresp.status ==){
error ;
} return (deliver);
} sub vcl_deliver { if(obj.hits >){
set resp.http.X-Cache ="cached";
}else{
set resp.http.X-Cache ="uncached";
} return (deliver);
} sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} + obj.status + " " + obj.response + {"</title>
</head>
<body>
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
<p>"} + obj.response + {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} + req.xid + {"</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
return (deliver);
}
#
# sub vcl_init {
# return (ok);
# }
#
# sub vcl_fini {
# return (ok);
# }

基本性能测试

1、单独业务功能

./ab -n  -c   http://localhost:8080/arch1/toIndex

2、Nginx+Varnish+基本业务

./ab -n  -c   http://localhost:80/arch1/toIndex

 

varnish应用的更多相关文章

  1. 利用varnish做Discuz论坛的缓存服务器

    实验背景:公司有一台BBS服务器,用的是LNMP的架构搭建的.正好手头有一台空闲的虚拟机,于是想着给BBS前端加一台缓存服务器.于是选定了varnish,搜了很多教程,跌跌撞撞的完成了配置.这其中很多 ...

  2. varnish 隐藏版本号

    varnish 隐藏方法: 修改default.vcl配置文件. 找到或添加 vcl_deliver 子程序,代码如下: 1 2 3 4 5 sub vcl_deliver {        unse ...

  3. [转]在windows环境中使用varnish

    varnish 的windows 版本下载地址: http://sourceforge.net/projects/cygvarnish/files/windows-zip-bundle/ 启动:var ...

  4. Varnish常用相关命令工具

    varnishd启动./varnishd  -f /usr/local/varnish-3.0.2/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1: ...

  5. Varnish介绍

    “Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang (http://www.vg.no) 使用3台Varnish代替了原来的12台squid,性能居然比以前 ...

  6. varnish 内置函数详细说明

    Subroutine列表 •vcl_recv 在请求开始时候被调用,在请求已经被接收到并且解析后调用.目的就是决定是否处理这个请求,怎么处理,使用哪个后端.vcl_recv以return结束,参数可以 ...

  7. varnish 4.0.3 域名访问的小问题

    1,若端口不是80 端口则匹配的时候必须加端口 if (req.http.host ~ "(?i)^var.test.aa:6081$") {set req.http.host = ...

  8. Varnish简介

    Varnish介绍: Varnish是一个反向HTTP代理,有时也被称为HTTP的加速器或网络加速器:它存在于真实服务器的前面(可能有多级代理),将来自于客户端的请求中的部分内容存储在自身的内存中,以 ...

  9. 学习varnish随笔

    Varnish是一款高性能.开源的反向代理服务器和缓存服务器.Varnish使用内存缓存文件来减少响应时间和网络带宽消耗.这个项目是由挪威的一家报纸Verdens Gang的网络分支起始的,其架构设计 ...

  10. varnish

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

随机推荐

  1. vue pdf下载

    主要技术栈是Vue,两个库: html2canvas npm地址 jspdf 具体实现代码如下: <template> <div class="priview_resume ...

  2. Go语言 之TCP聊天室

    服务端流程图如下: package main import ( "fmt" "net" ) // 客户端结构体 type Client struct { //用 ...

  3. cmake语法入门记录

    刚刚开始学习ROS,打算入机器人的坑了,参考教材是<ROS及其人开发实践>胡春旭编著 机械工业出版社 华章科技出品.本来以为可以按照书上的步骤一步步来,但是,too young to si ...

  4. Spring Cloud|高可用的Eureka集群服务

    Eureka,作为spring cloud的服务发现与注册中心,在整个的微服务体系中,处于核心位置.单一的eureka服务,显然不能满足高可用的实际生产环境,这就要求我们配置一个能够应对各种突发情况, ...

  5. Elasticsearch的java客户端JEST的操作

    准备 把Elasticsearch安装好 安装百度上有很多资料. 导入必要的包 <parent> <groupId>org.springframework.boot</g ...

  6. pwn学习日记Day22 《程序员的自我修养》读书笔记

    知识杂项 软连接 命令: ln -s 原文件 目标文件 特征: 1.相当于windows的快捷方式 2.只是一个符号连接,所以软连接文件大小都很小 3.当运行软连接的时候,会根据连接指向找到真正的文件 ...

  7. python核心模块方法

    ********************os模块: os.remove() 删除文件 os.unlink() 删除文件 os.rename() 重命名文件 os.listdir() 列出指定目录下所有 ...

  8. linux下怎么用ssh连接另一台linux服务器

    linux系统大家都知道是服务器版本一般都没有图像界面,通过字符界面操作.用ssh远程方式远程,如果要从一台linux远程到另外一台系统应该怎么操作呢本经验咗嚛以cenots7为例演示   方法/步骤 ...

  9. [Scikit-learn] 1.1 Generalized Linear Models - Logistic regression & Softmax

    二分类:Logistic regression 多分类:Softmax分类函数 对于损失函数,我们求其最小值, 对于似然函数,我们求其最大值. Logistic是loss function,即: 在逻 ...

  10. 《精通并发与Netty》学习笔记(07 - 基于Thrift实现Java与Python的RPC调用)

    上节我们介绍了基于Thrift实现java与java的RPC调用,本节我们基于Thrift实现Java与Python的RPC调用 首先,修改data.thirft文件,将命名空间由java改为py n ...