简体   繁体   English

如何使用nginx提供Clojure页面

[英]How to serve Clojure pages with nginx

I set up a home server with ubuntu and ngingx and I can serve static files. 我用ubuntu和ngingx设置了一个家庭服务器,我可以提供静态文件。 Now I want to test some clojure files but I am not clear about how to do this. 现在我想测试一些clojure文件,但我不清楚如何做到这一点。 For php this seems very easy, for instance in this tutorial he adds a location for php files. 对于php来说这似乎很容易,例如在本教程中他为php文件添加了一个位置。 Is that all I need to do, just indicate where Clojure files are in the config file? 这就是我需要做的,只需指出Clojure文件在配置文件中的位置?

I have the Web Development with Clojure by Dmitry Sotnikov and he talks about deployment but not specifically about nginx. 我有Dmitry Sotnikov 与Clojure进行的Web开发,他谈到了部署,但没有具体谈到nginx。

Can you point me in the right direction where I can find documentation about this? 你能指出我正确的方向,我可以找到有关这方面的文件吗?

Please try Nginx-Clojure module. 请尝试Nginx-Clojure模块。 You can run clojure Ring handlers with Nginx without any Java Web Server, eg. 您可以在没有任何Java Web服务器的情况下使用Nginx运行clojure Ring处理程序,例如。 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). 您需要在某个端口(例如8080)启动lein ring server (使用lein-ring插件)。 Nginx will listen at 80 port and forward requests to 8080. Here is a sample nginx config: Nginx将侦听80端口并将请求转发到8080.这是一个示例nginx配置:

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 ). path-to-public-dir更改静态文件所在的目录( resources / public )。 Nginx will server static files (if file found) and forward other requests to ring server. Nginx将服务器静态文件(如果找到文件)并将其他请求转发给响铃服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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