如何将nginx配置为jetty的代理? [英] How do I configure nginx as proxy to jetty?

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

问题描述

我一直在尝试将nginx设置为jetty的代理。我想按照此答案中的说明执行操作但是对于Jetty没有响。

I've been trying to set up nginx as proxy to jetty. I want to do something as explained in this answer but for Jetty not ring.

我创建了一个 .war 并将其放入〜/ jetty / jetty-dist / webapps / web_test-0.1.0-SNAPSHOT-standalone.war

I've created a .war and I placed it in ~/jetty/jetty-dist/webapps/web_test-0.1.0-SNAPSHOT-standalone.war

说,我想要使用域名example.com与IP地址198.51.100.0。

Say, I want to use the domain example.com with ip address 198.51.100.0.

我还复制了 / etc / nginx / sites-available / default 进入文件 example.com ,我将它放在同一目录中。

I've also copied /etc/nginx/sites-available/default into the file example.com and I have it in the same directory.

可以在我的情况下,你帮我配置nginx作为jetty的代理吗?我知道网上有很多关于如何做到这一点的参考文献,但它们都不同,我感到困惑。

Can you help me configure nginx as proxy to jetty in my case? I know there are many references online about how to do this but they are all different and I got confused.

我需要在nginx中做出哪些具体的更改?我需要在jetty.xml中进行哪些更改?我是否需要进行任何其他更改?我的应用程序是否会在example.com/index.html上提供?

What specific changes do I need to make in nginx? What changes do I need to make in jetty.xml? Do I need to make any other changes? Will my app be served at example.com/index.html?

nginx的当前状态复制如下:

Current state of nginx is copied below:

upstream jetty {
  server 127.0.0.1:8080 fail_timeout=0
}

server {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name localhost;

        location / {
                proxy_pass http://jetty

                try_files $uri $uri/ =404;
        }






编辑

我想知道是否需要使用Jetty。在此设置中,他只使用铃声,这看起来非常简单?使用jetty可以获得什么?

I was wondering if I need to use Jetty at all. In this setup he just uses ring, which seems super easy? What do I gain by using jetty?

推荐答案

如何配置nginx工作用java服务器。在示例中使用了Jetty。

How to configure nginx to work with a java server. In the example Jetty is used.

编辑 / etc / nginx / sites-available / hostname

server {
  listen       80;
  server_name  hostname.com;

  location / {
    proxy_pass       http://localhost:8080;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
  }
}

考虑禁用对端口8080的外部访问:

Consider disabling external access to port 8080:

/sbin/iptables -A INPUT -p tcp -i eth0 --dport 8080 -j REJECT --reject-with tcp-reset

一个示例Jetty配置( jetty.xml )可能类似于:

An example Jetty configuration (jetty.xml) might resemble:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!--
 | http://eclipse.org/jetty/documentation/current/configuring-connectors.html
 +-->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
    <Set name="secureScheme">https</Set>
    <Set name="securePort"><Property name="jetty.tls.port" default="8443" /></Set>
    <Set name="outputBufferSize">65536</Set>
    <Set name="requestHeaderSize">8192</Set>
    <Set name="responseHeaderSize">8192</Set>
  </New>
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ServerConnector">
        <Arg name="server"><Ref refid="Server" /></Arg>
        <Arg name="acceptors" type="int"><Property name="http.acceptors" default="-1"/></Arg>
        <Arg name="selectors" type="int"><Property name="http.selectors" default="-1"/></Arg>
        <Arg name="factories">
          <Array type="org.eclipse.jetty.server.ConnectionFactory">
            <Item>
              <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                <Arg name="config"><Ref refid="httpConfig" /></Arg>
              </New>
            </Item>
          </Array>
        </Arg>
        <Set name="host"><Property name="jetty.host" default="localhost" /></Set>
        <Set name="port"><Property name="jetty.port" default="8080" /></Set>
      </New>
    </Arg>
  </Call>
</Configure>

这将导致Jetty收听 localhost:8080 和nginx进行重定向来自 domain.com:80 的请求到Jetty服务器。

This will cause Jetty to listen on localhost:8080 and nginx to redirect requests from domain.com:80 to the Jetty server.

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

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