简体   繁体   中英

How to serve Clojure pages with nginx

I set up a home server with ubuntu and ngingx and I can serve static files. Now I want to test some clojure files but I am not clear about how to do this. For php this seems very easy, for instance in this tutorial he adds a location for php files. Is that all I need to do, just indicate where Clojure files are in the config file?

I have the Web Development with Clojure by Dmitry Sotnikov and he talks about deployment but not specifically about nginx.

Can you point me in the right direction where I can find documentation about this?

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 .

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM