###you can uncomment next two lines for easy debug ###Warning: if master_process is off, there will be only one nginx worker running. Only use it for debug propose. #daemon off; #master_process off; #user nobody; # 指定worker数量,也就是jvm的数量 #worker_processes 1; # 根据CPU自动设定worker数量 worker_processes auto; #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; jvm_path auto; ### Set my app jars and resources, it must include nginx-clojure runtime jar,e.g. nginx-clojure-0.5.1.jar and ### for clojure user clojure runtime jar is also needed. ### See http://nginx-clojure.github.io/directives.html#jvm_classpath jvm_var nginxHome '/Users/zhaoqin/baidusync/temp/202202/07/001/nginx-clojure-0.5.2'; #jvm_var nginxHome '/Users/zhaoqin1/temp/202202/02/001/nginx-clojure-0.5.2'; jvm_classpath "#{nginxHome}/libs/*:#{nginxHome}/jars/*"; ###jvm heap memory #jvm_options "-Xms1024m"; #jvm_options "-Xmx1024m"; #for enable java remote debug uncomment next two lines jvm_options "-Xdebug"; jvm_options "-Xrunjdwp:server=y,transport=dt_socket,address=840#{pno},suspend=n"; ###threads number for request handler thread pool on jvm, default is 0. ###check more details from #jvm_workers 8; jvm_handler_type 'java'; jvm_init_handler_name 'com.bolingcavalry.handlerdemo.MyInitHandler'; # 增加一个共享内存的初始化分配,类型tiny,空间1M,键数量8K shared_map uri_access_counters tinymap?space=1m&entries=8096; server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #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; } location /clojure { handler_type 'clojure'; handler_code ' (fn[req] { :status 200, :headers {"content-type" "text/plain"}, :body "Hello Clojure & Nginx!" }) '; } location /java { content_handler_type 'java'; content_handler_name 'com.bolingcavalry.simplehello.HelloHandler'; } location /contentdemo { # 第一个自定义属性 content_handler_property foo.name 'foo.value'; # 第二个自定义属性 content_handler_property bar.name 'bar.value'; content_handler_name 'com.bolingcavalry.handlerdemo.MyContentHandler'; # log handler类型是java log_handler_type java; # log handler的执行类 log_handler_name 'com.bolingcavalry.handlerdemo.MyLogHandler'; # 自定义属性,在MyLogHandler中作为是否打印User Agent的开关 log_handler_property log.user.agent on; # 自定义属性,在MyLogHandler中作为日志目录 log_handler_property log.file.path logs/contentdemo.log; } # 1. 定义变量,用于保存路径 set $myhost ""; location /myproxy { # 指定access handler的类型是java access_handler_type 'java'; # 指定access handler的执行类类 access_handler_name 'com.bolingcavalry.handlerdemo.BasicAuthHandler'; rewrite_handler_type 'java'; # 2. java代码中为变量赋值 rewrite_handler_name 'com.bolingcavalry.handlerdemo.MyRewriteProxyPassHandler'; # 3. 用变量的值作为地址进行跳转 proxy_pass $myhost; } # header filter的demo location /headerfilterdemo { content_handler_type 'java'; content_handler_name 'com.bolingcavalry.simplehello.HelloHandler'; # header filter的类型是java header_filter_type 'java'; # header filter的类 header_filter_name 'com.bolingcavalry.filterdemo.RemoveAndAddMoreHeaders'; } # body filter的demo,response body是字符串类型 location /stringbodyfilterdemo { content_handler_type 'java'; content_handler_name 'com.bolingcavalry.simplehello.HelloHandler'; # body filter的类型是java body_filter_type 'java'; # body filter的类 body_filter_name 'com.bolingcavalry.filterdemo.StringFacedUppercaseBodyFilter'; } location /largebody { content_handler_type 'clojure'; content_handler_code ' (do (use \'[nginx.clojure.core]) (fn[req] {:status 200 :headers {} :body (for [i (range 1024)] "123456789\n")}) )'; } location /streambodyfilterdemo { # body filter的类型是java body_filter_type java; body_filter_name 'com.bolingcavalry.filterdemo.StreamFacedBodyFilter'; proxy_http_version 1.1; proxy_buffering off; proxy_pass http://localhost:8080/largebody; } location /heapbasedcounter { content_handler_type 'java'; content_handler_name 'com.bolingcavalry.sharedmap.HeapSaveCounter'; } location /sharedmapbasedcounter { content_handler_type 'java'; content_handler_name 'com.bolingcavalry.sharedmap.SharedMapSaveCounter'; } # location /groovy { # handler_type 'groovy'; # handler_code ' # import nginx.clojure.java.NginxJavaRingHandler; # import java.util.Map; # public class HelloGroovy implements NginxJavaRingHandler { # public Object[] invoke(Map request){ # return [200, //http status 200 # ["Content-Type":"text/html"], //headers map # "Hello, Groovy & Nginx!"]; //response body can be string, File or Array/Collection of them # } # } # '; # } # } }