2013-12-20 18 views
0

我有這樣的設置:如何將nginx作爲代理運行到碼頭?

我在我用作服務器的ubuntu機器上安裝了nginx和Jetty。我測試了Jetty,它運行於0.0.0.0.:8080,我看到Jetty歡迎頁面。

我將使用的域名是nomilkfor.me。 nginx conf文件位於/etc/nginx/sites-available/nomilkfor.me.conf

我在另一臺筆記本電腦(OSX)上編程,我用lein創建了一個項目web_test。我創建了文件web_test,當我運行lein ring server時,我在瀏覽器上看到core.clj的內容。

最初,我在this answer之後建立了nginx conf文件,但是我無法使它工作。

我想問我如何修復下面的conf文件(以及我的問題)以及如何將nginx的web_test作爲代理部署到碼頭。

我粘貼conf文件下方,添加我的問題,每個指令:

# what should the ip address and port be? 
# i assume this instructs nginx to send request it receives on port 80 to Jetty server 
upstream ring { 
    server ????? fail_timeout=0; 
} 

# what directory do I need to enter here? 
# do I use the clojure project root? 
# do I use ~/web_test/src ? 
server { 
    root /?????; 

    # make site accessible from http://localhost 
    server_name nomilkfor.me; 

    location/{ 
     # first attempt to serve request as file 
     try_files $uri $uri/ @ring; 
    } 

    # we will need to understand these settings 
    location @ring { 
     proxy_redirect off; 
     proxy_buffering off; 
     proxy_set_header Host $http_host; 

     # what do I use here??? 
     # is http://ring; correct??? 
     proxy_pass http://ring; 
    } 

    location ~ ^(assets|images|javascript|stylesheets|system)/ { 
     expires max; 
     add_header Cache-Control public; 
    } 
} 

注:這是我關於同一主題的第三個問題,但我還是沒能解決。感謝所有的幫助。

回答

1

server應該包含IP:上游服務器的端口(碼頭是你的情況下)。

root是您的靜態文件所在的Web根文件夾。 Nginx會在那裏查找文件。這樣的文件夾通常被命名爲「公共」,因爲它可以從外部訪問。例如/js/bootstrap.min.js請求將使nginx搜索public/js/bootstrap.min.js(請參閱try_files指令)。如果這樣的文件未找到請求將被轉發到碼頭服務器。

+0

謝謝,我會試試。但現在我有另一個問題,碼頭不適合我。我已經在這裏和超級用戶關於碼頭問過幾個問題。我甚至無法刪除它。你能推薦另一臺服務器,我可以使用,而不是碼頭?我研究樹脂,但它似乎不適合初學者。有沒有更容易使用的服務器,我可以嘗試? – Zeynel