【问题标题】:How do I run nginx as proxy to jetty?如何运行 nginx 作为码头的代理?
【发布时间】:2013-12-21 03:29:32
【问题描述】:

我有这个设置:

我在用作服务器的 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.war 文件,当我运行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;
    }
}

注意:这是我关于同一主题的第三个问题,但我仍然无法解决。感谢大家的帮助。

【问题讨论】:

    标签: java nginx clojure proxy jetty


    【解决方案1】:

    server 应该包含上游服务器的 ip:port(码头是你的情况)。

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

    【讨论】:

    • 谢谢,我会试试的。但现在我遇到了另一个问题,Jetty 不适合我。我已经在这里和 SuperUser 中提出了几个关于码头的问题。我什至无法删除它。你能推荐另一个我可以用来代替码头的服务器吗?我研究了树脂,但似乎它不适合初学者。有没有更好用的服务器可以试试?
    猜你喜欢
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多