2013-12-17 45 views
4

我使用ubuntu和ngingx設置了家庭服務器,並且可以提供靜態文件。現在我想測試一些clojure文件,但我不清楚如何做到這一點。對於php來說,這看起來很簡單,例如in this tutorial他爲php文件添加了一個位置。這就是我需要做的,只是指出Clojure文件在配置文件中的位置?如何使用nginx服務Clojure頁面

我有Web開發與Clojure Dmitry Sotnikov和他談論部署,但不是專門關於nginx。

你能指點我在正確的方向,我可以找到有關此文件?

+1

還閱讀:http://stackoverflow.com/questions/7787911/compojure-lein-ring-in-production – edbond

回答

6

考慮下一步設置:

nginx -> ring server (jetty) 

你需要開始lein ring server(使用lein-ring插件)一些端口(比如8080)上。 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; 
    } 
} 

變化路徑到公共目錄到目錄中的靜態文件駐留(資源/公共 )。 Nginx將服務器靜態文件(如果找到文件)並轉發其他請求到響鈴服務器。

+4

雷音不應從生產環境中運行。使用lein uberjar創建一個服務器jar。 – noisesmith

+0

我創建了一個名爲「guestbook」的項目,並且我在'localhost:3000'上運行了'lein ring server',並且在瀏覽器中看到了「Hello World」。我將conf文件從「8080」更改爲「3000」(正確?),但現在我很困惑我需要放置項目文件的位置。此時他們在'〜/留言簿'中。你能幫忙嗎? – Zeynel

+1

很好,現在在nginx配置中改變:'root/home/zeynel/guestbook/resources/public'(確保文件夾存在)並訪問http:// localhost /。這應該會擊中你的戒指服務器。 – edbond

6

請嘗試Nginx-Clojure模塊。你可以在沒有任何Java Web服務器的情況下使用Nginx運行clojure Ring處理程序,例如。碼頭。 更進一步它非常快。基準可以找到HERE

enter image description here

相關問題