nginx-clojure Code
Nginx-Clojure is a Nginx module for embedding Clojure or Java programs
Brought to you by:
xfeep
File | Date | Author | Commit |
---|---|---|---|
conf | 2015-11-06 |
![]() |
[7a4e43] fix some typo errors |
src | 2015-11-09 |
![]() |
[9b2680] in c module integrating example remove unnecess... |
.gitignore | 2015-11-06 |
![]() |
[fd1cab] add an integration example for C module |
README.md | 2015-11-06 |
![]() |
[a08fca] typo error the--> get |
pom.xml | 2015-11-06 |
![]() |
[fd1cab] add an integration example for C module |
This simple example show how a nginx C module integrates existing Java libraries by using nginx-clojure.
In this example we have a nginx c module say x-module which will send "HELLO, WORLD" to the client.
When a request whose uri is matched with the location using x-module's directive say "x"
:
my_array
to "hello, world"my_array
and set the upper-cased result back to variable my_array
my_array
, viz "HELLO, WORLD" and sent it to the client.## suppose nginx_clojure_root is /home/who/git/nginx-clojure
$ export nginx_clojure_root=/home/who/git/nginx-clojure
## at the nginx source dir
$ auto/configure --add-module=${nginx_clojure_root}/src/c \
--add-module=${nginx_clojure_root}/example-projects/c-module-integration-example/src/c
make -j
Then we'll get objs/nginx
viz. the executable nginx binary file.
$ cd $nginx_clojure_root/example-projects/c-module-integration-example
$ mvn package
Then we'll get target/c-module-integration-example-0.0.1.jar
.
See $nginx_clojure_root/example-projects/c-module-integration-example/conf/nginx.conf
Make sure jvm_classpath
and other nginx-clojure directives are rightly configurated.
## run nginx
$ ./nginx
## test it by curl
$ curl -v http://localhost:8080/hello
Then we 'll get the result :
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /hello HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.8.0
< Date: Fri, 06 Nov 2015 16:36:15 GMT
< Content-Type: text/plain
< Content-Length: 12
< Connection: keep-alive
<
HELLO, WORLD