How to serve Clojure pages with nginx How to serve Clojure pages with nginx nginx nginx

How to serve Clojure pages with nginx


Please try Nginx-Clojure module. You can run clojure Ring handlers with Nginx without any Java Web Server, eg. Jetty.Further more it 's very fast. The benchmarks can be found HERE.

enter image description here


Consider next setup:

nginx -> ring server (jetty)

You need to start lein ring server (using lein-ring plugin) on some port (say 8080). Nginx will listen at 80 port and forward requests to 8080.Here is a sample nginx config:

upstream ring {  server 127.0.0.1:8080 fail_timeout=0;}server {    root <path-to-public-dir>;    # Make site accessible from http://localhost/    server_name localhost;    location / {        # First attempt to serve request as file        try_files $uri $uri/ @ring;    }    location @ring {        proxy_redirect off;        proxy_buffering off;        proxy_set_header Host $http_host;        proxy_pass http://ring;    }    location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {        expires     max;        add_header  Cache-Control public;    }}

Change path-to-public-dir to directory where your static files reside (resources/public).Nginx will server static files (if file found) and forward other requests to ring server.