Accept cookies for analytics, social media, and advertising, or learn more and adjust your preferences. These cookies are on by default for visitors outside the UK and EEA. Privacy Notice.
Nginx-Clojure is a NGINX module for embedding Clojure or Java or Groovy programs, typically those Ring <ring-clojure/ring/blob/master/SPEC> based handlers.
There is a simple example about Java handler.
In nginx.conf
location /myJava {
handler_type 'java';
handler_name 'mytest.Hello';
}
In Hello.java
package mytest;
import static nginx.clojure.MiniConstants.*;
import java.util.HashMap;
import java.util.Map;
public class Hello implements NginxJavaRingHandler {
@Override
public Object[] invoke(Map<String, Object> request) {
return new Object[] {
NGX_HTTP_OK, //http status 200
ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map
"Hello, Java & NGINX!" //response body can be string, File or Array/Collection of them
}
}
}
More details can be found in nginx-clojure.github.io