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-03 |
![]() |
[df8144] fix some typo errors |
resources | 2015-10-06 |
![]() |
[f695ea] example project: use PubSubTopic instead of bro... |
src | 2015-10-25 |
![]() |
[c2dec7] update example project |
test | 2015-10-25 |
![]() |
[c2dec7] update example project |
.gitignore | 2017-04-22 |
![]() |
[57e14e] add set-cookie test & update gitignore |
README.md | 2015-10-26 |
![]() |
[90080e] example: fix download file name |
project.clj | 2017-05-06 |
![]() |
[22b74f] change version to 0.4.5 |
A basic example about nginx-clojure & clojure web dev. It uses:
* Compojure (for uri routing)
* Hiccup (for html rendering)
* Websocket API & Sub/Pub API (to demo a simple chatroom)
* ring.middleware.reload (for auto-reloading modified namespaces in dev environments)
Suppose our example project path is /home/who/git/nginx-clojure/example-projects/clojure-web-example
.
$ export EXAMPLE_ROOT=/home/who/git/nginx-clojure/example-projects/clojure-web-example
$ cd $EXAMPLE_ROOT
$ lein with-profile embed run
Then browser http://localhost:8080/
When we do some modifications the related namespaces will be auto-reloaded
so that we need not restart lein repl.
$ cd $EXAMPLE_ROOT
## build a standalone clojure-web-example-embed.jar at target/uberjar/
$ lein with-profile embed uberjar
## suppose we deploy it to directory testdeploy
$ cd testdeploy
## make sure directory testdeploy has file clojure-web-example-embed.jar and logback.xml
## otherwise we need copy them to it. Then run the server by below command.
$ java -cp . -jar clojure-web-example-embed.jar 8080
$ cd $EXAMPLE_ROOT
## build a standalone clojure-web-example-default.jar at target/uberjar/
$ lein uberjar
We can download the binaries of Nginx compiled with Nginx-Clojure or we can compile nginx-clojure with
our nginx by this guide.
$ cd /tmp
$ wget https://sourceforge.net/projects/nginx-clojure/files/nginx-clojure-0.4.3.tar.gz
$ tar -xzvf nginx-clojure-0.4.3.tar.gz
$ sudo mv nginx-clojure-0.4.3 /opt/
## create user nginx who will be run as by Nginx Worker processes
## we have specified this by directive `user nginx nginx;` in nginx.conf
$ sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
$ sudo mkdir -p /opt/nginx-clojure-0.4.3/libs/res
$ sudo cp $EXAMPLE_ROOT/target/uberjar/clojure-web-example-default.jar /opt/nginx-clojure-0.4.3/libs
$ sudo cp $EXAMPLE_ROOT/conf/logback.xml /opt/nginx-clojure-0.4.3/libs/res
$ sudo cp $EXAMPLE_ROOT/conf/nginx.conf /opt/nginx-clojure-0.4.3/conf/nginx.conf
$ sudo cp -R $EXAMPLE_ROOT/resources/public /opt/nginx-clojure-0.4.3/
## make /opt/nginx-clojure-0.4.3 searchable
$ sudo chmod o+x /opt
$ sudo chmod o+x /opt/nginx-clojure-0.4.3
$ cd /opt/nginx-clojure-0.4.3
$ sudo cp jars/nginx-clojure-0.4.3.jar libs/
## rename nginx-xxx to nginx
$ sudo mv nginx-linux-x64 nginx
## grant minimal permissions for safety
$ sudo chmod o+rx $(sudo find libs -type d)
$ sudo chmod o+r $(sudo find libs -type f)
$ sudo chmod -R -w public
$ sudo chown -R nginx public logs temp
$ sudo chmod -R u+rwx logs temp
$ sudo chmod u+rx $(sudo find public -type d)
$ sudo chmod u+r $(sudo find public -type f)
$ sudo ./nginx -t
##start and we can check error in file logs/error.log
$ sudo ./nginx
## list nginx processes
$ ps aux | grep nginx
##reload when configuration changes without stopping our service.
$ sudo ./nginx -s reload
##stop
$ sudo ./nginx -s stop