如何运行nginx作为代理到jetty? [英] How do I run nginx as proxy to jetty?

查看:569
本文介绍了如何运行nginx作为代理到jetty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个设置:

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

I installed nginx and Jetty on an ubuntu machine that I am using as the server. I tested Jetty and it is running on 0.0.0.0.:8080 and I see the Jetty Welcome page.

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

The domain that I will be using is nomilkfor.me. The nginx conf file is in /etc/nginx/sites-available/nomilkfor.me.conf.

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

I am programming on an another laptop (OSX) and I created a project web_test with lein. I created a .war file of web_test and when I run lein ring server I see the content of core.clj on the browser.

最初,我设置了nginx conf文件,但此答案,但我无法这行得通。

Initially, I set up nginx conf file after this answer but I could not make it work.

我想问我如何修复下面的conf文件(以我的问题),以及如何使用nginx作为代理来部署web_test到jetty。

I want to ask how I can fix the conf file below (with my questions) and how to deploy web_test with nginx as proxy to jetty.

我粘贴了下面的conf文件并添加了我对每个指令的问题:

I pasted the conf file below and added my questions for each directive:

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

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

Note: This is my third question about the same subject but I still could not solve. Thanks for all the help.

  • Can I use Clojure with nginx?
  • How to serve clojure pages with nginx?

推荐答案

服务器应包含上游服务器的ip:port(您的情况是jetty)。

server should contains ip:port of upstream server (jetty is your case).

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

root is the web root folder where your static files reside. Nginx will look for files there. Such folder usually named 'public' because it's accessible from outside. For example /js/bootstrap.min.js request will make nginx search for public/js/bootstrap.min.js (see try_files directive). If such file not found request will be forwarded to jetty server.

这篇关于如何运行nginx作为代理到jetty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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