Created
September 28, 2012 00:35
-
-
Save lichengwu/3797290 to your computer and use it in GitHub Desktop.
intranet cache config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is a basic VCL configuration file for varnish. See the vcl(7) | |
#man page for details on VCL syntax and semantics. | |
# | |
#Default backend definition. Set this to point to your content | |
#server. | |
# | |
backend default { | |
.host = "hostname1.com"; | |
#.host = "meituan.com"; | |
#.host = "debug.ct.dev.sankuai.com"; | |
#.port = "80"; | |
} | |
#backend mtct { | |
# .host = "hostname2.com"; | |
#} | |
#backend mtct_st { | |
# .host = "hostname.com"; | |
#} | |
# | |
#Below is a commented-out copy of the default VCL logic. If you | |
#redefine any of these subroutines, the built-in logic will be | |
#appended to your code. | |
# | |
acl access { | |
"192.168.0.220"; | |
"localhost"; | |
"s3"; | |
"192.168.60.216"; | |
} | |
sub vcl_recv { | |
unset req.http.Cookie; | |
set req.grace = 3m; | |
#set req.url = regsub(req.url,"^(.+)(&token=.+)$","\1:"); | |
if(req.url ~ "/varnish-ping"){ | |
error 200 "OK"; | |
} | |
if(!client.ip ~ access){ | |
error 405 "Access Denied !"; | |
} | |
#remove req.http.X-Forwarded-For; | |
#std.syslog(180, "RECV: " + req.http.host + req.url); | |
if(req.url ~ ".*/attachment/.*"){ | |
set req.http.host = "ct.sankuai.com"; | |
set req.url = regsub(req.url,"/attachment/(.+)(&token=.+)$","/cache/attachment/\1"); | |
#return (lookup); | |
} | |
#else{ | |
# error 404 "Illegal Request!"; | |
#} | |
return (lookup); | |
} | |
sub vcl_fetch { | |
#if (!obj.cacheable) { | |
# return (pass); | |
#} | |
#if (obj.http.Set-Cookie) { | |
# return (pass); | |
#} | |
#if (beresp.status == 301 || beresp.status == 307) { | |
#set req.url = regsub(beresp.http.Location, "^http://[^/]*", ""); | |
#set req.http.vcIP = regsub(beresp.http.Location, "^http://([^/:]*).*", "\1"); | |
#set req.http.host="st.ct.sankuai.com"; | |
#set beresp.status = 200; | |
#return(restart); | |
#} | |
if (beresp.status == 500) { | |
#set beresp.cacheable = false; | |
#return (pass); | |
error 404 "File not Found!"; | |
} | |
if (beresp.http.Content-Length == "0" || beresp.http.Content-Length == "" ) { | |
return (hit_for_pass); | |
} | |
set beresp.ttl = 90d; | |
set beresp.grace = 5m; | |
return (deliver); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user root; | |
worker_processes 2; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
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; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
server { | |
listen 80; | |
server_name 192.168.0.220; | |
#charset koi8-r; | |
#access_log logs/host.access.log main; | |
#varnish_host for get cache | |
set $varnish_host http://192.168.0.220:9350; | |
# ping for check varnish health | |
location ~ varnish-ping$ { | |
allow all; | |
proxy_pass $varnish_host; | |
} | |
# for contract | |
location / { | |
allow all; | |
root html; | |
proxy_pass $varnish_host; | |
secure_link $arg_token,$arg_expire; | |
secure_link_md5 my_keys_string$uri$arg_expire; | |
if ($secure_link = "") { | |
return 403; | |
} | |
if ($secure_link = "0") { | |
return 404; | |
} | |
#if ( $args ~ ^(.+)(&token=.+)$ ) { | |
# set $args $1; | |
# set $varnish_host http://192.168.0.220:9350; | |
# rewrite ^(.+)$ $varnish_host$uri?$1 break; | |
# #rewrite ^(.*)$ "http://www.meituan.com"$args break; | |
#} | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# 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 8000; | |
# listen somename:8080; | |
# server_name somename alias another.alias; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
# HTTPS server | |
# | |
#server { | |
# listen 443; | |
# server_name localhost; | |
# ssl on; | |
# ssl_certificate cert.pem; | |
# ssl_certificate_key cert.key; | |
# ssl_session_timeout 5m; | |
# ssl_protocols SSLv2 SSLv3 TLSv1; | |
# ssl_ciphers HIGH:!aNULL:!MD5; | |
# ssl_prefer_server_ciphers on; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment