nginx-clojure - Browse Files at SourceForge.net
这里我选择的是0.5.2版本,下载之后需要进行解压

- <repositories>
- <repository>
- <id>clojars.orgid>
- <url>http://clojars.org/repourl>
- repository>
- repositories>
-
- <dependencies>
- <dependency>
- <groupId>nginx-clojuregroupId>
- <artifactId>nginx-clojureartifactId>
- <version>0.5.2version>
- dependency>
- dependencies>
- package org.example;
-
- import static java.util.jar.Attributes.Name.CONTENT_TYPE;
- import static nginx.clojure.MiniConstants.NGX_HTTP_OK;
-
- import nginx.clojure.java.ArrayMap;
- import nginx.clojure.java.NginxJavaRingHandler;
-
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.Map;
-
- public class Main implements NginxJavaRingHandler {
-
- @Override
- public Object[] invoke(Map
map) throws IOException { - return new Object[] {
- NGX_HTTP_OK, //http status 200
- ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map
- "Hello, Nginx clojure! " + LocalDateTime.now() //response body can be string, File or Array/Collection of them
- };
- }
- }

注意这个name,就是上面写的java代码里的全类名
- location /java {
- content_handler_type 'java';
- content_handler_name 'org.example.Main';
- }
