如何将nginx作为jetty的代理运行?

时间:2013-12-20 14:37:34

标签: java nginx clojure proxy jetty

我有这个设置:

我在我用作服务器的ubuntu机器上安装了nginx和Jetty。我测试了Jetty,它运行在0.0.0.0.:8080,我看到了Jetty Welcome页面。

我将使用的域名为nomilkfor.me。 nginx conf文件位于/etc/nginx/sites-available/nomilkfor.me.conf

我在另一台笔记本电脑(OSX)上编程,我用lein创建了一个项目web_test。我创建了一个.war web_test文件,当我运行lein ring server时,我在浏览器上看到core.clj的内容。

最初,我在this answer之后设置了nginx conf文件,但我无法使其正常工作。

我想问一下如何修复下面的conf文件(我的问题)以及如何使用nginx作为jetty的代理部署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 个答案:

答案 0 :(得分:1)

server应该包含ip:上游服务器的端口(jetty就是你的情况)。

root是静态文件所在的Web根文件夹。 Nginx会在那里寻找文件。这样的文件夹通常命名为“公共”文件夹。因为它可以从外面访问。例如,/js/bootstrap.min.js请求将使nginx搜索public/js/bootstrap.min.js(请参阅try_files指令)。如果找不到这样的文件请求将被转发到jetty服务器。

相关问题