如何使用 nginx 服务 Clojure 页面 [英] How to serve Clojure pages with nginx

查看:12
本文介绍了如何使用 nginx 服务 Clojure 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 ubuntu 和 ngingx 设置了一个家庭服务器,我可以提供静态文件.现在我想测试一些 clojure 文件,但我不清楚如何执行此操作.对于 php 这似乎很容易,例如 在本教程中 他为 php 添加了一个位置文件.这就是我需要做的,只需要指出 Clojure 文件在配置文件中的位置吗?

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?

我有 Dmitry Sotnikov 的 Web Development with Clojure,他谈论的是部署,但不是专门谈论 nginx.

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?

推荐答案

考虑下一个设置:

nginx -> ring server (jetty)

您需要在某些服务器上启动 lein ring server(使用 lein-ring 插件)端口(比如 8080).Nginx 将监听 80 端口并将请求转发到 8080.这是一个示例 nginx 配置:

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;
    }
}

path-to-public-dir 更改为静态文件所在的目录 (resources/public).Nginx 将服务静态文件(如果找到文件)并将其他请求转发到环服务器.

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.

这篇关于如何使用 nginx 服务 Clojure 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆