Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user www www;
- worker_processes 2;
- error_log /home/wwwlogs/nginx_error.log crit;
- pid /usr/local/openresty/nginx/logs/nginx.pid;
- google_perftools_profiles /tmp/tcmalloc;
- worker_rlimit_nofile 51200;
- events {
- use epoll;
- worker_connections 51200;
- }
- http {
- default_type text/html;
- upstream redis {
- server 127.0.0.1:6379;
- keepalive 1024;
- }
- server {
- listen 8080;
- root /home/wwwroot;
- index index.html;
- }
- server {
- listen 80;
- root /home/wwwroot;
- index index.html;
- location = /proxy {
- proxy_pass http://127.0.0.1:8080/;
- }
- location = /redis {
- internal;
- set $redis_key $arg_key;
- redis_pass redis;
- }
- location = /redis2 {
- internal;
- set $exptime $arg_exptime;
- set $key $arg_key;
- redis2_query set $key $echo_request_body;
- redis2_query expire $key $exptime;
- redis2_pass redis;
- }
- location / {
- default_type 'text/html';
- set $key $uri;
- set $exptime 300;
- content_by_lua '
- -- work like the srcache module
- local resa = ngx.location.capture("/redis",
- { method = ngx.HTTP_GET,
- args = { key = ngx.var.key } })
- if resa.status == 200 then
- ngx.say(resa.body)
- else
- local resb = ngx.location.capture("/proxy")
- if resb.status == ngx.HTTP_OK then
- ngx.say(resb.body)
- local resc = ngx.location.capture("/redis2",
- { method = ngx.HTTP_PUT,
- body = resb.body,
- args = { key = ngx.var.key, exptime = ngx.var.exptime } })
- else
- ngx.exit(ngx.HTTP_NOT_FOUND)
- end
- end
- -- update the redis cache from the proxy even the keys get hit
- if not resb then
- local resb = ngx.location.capture("/proxy")
- if resb.status == ngx.HTTP_OK then
- local resc = ngx.location.capture("/redis2",
- { method = ngx.HTTP_PUT,
- body = resb.body,
- args = { key = ngx.var.key, exptime = ngx.var.exptime } })
- else
- ngx.exit(ngx.HTTP_NOT_FOUND)
- end
- end
- ';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement