如何将nginx配置为jetty的代理?

Zey*_*nel 12 java jetty nginx ring

我一直在尝试将nginx设置为jetty的代理.我想做一些像这个答案中解释的但是Jetty没有响.

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

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

我也复制/etc/nginx/sites-available/default到文件中,example.com并将它放在同一目录中.

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

我需要在nginx中进行哪些具体更改?我需要在jetty.xml中进行哪些更改?我是否需要进行任何其他更改?我的应用会在example.com/index.html上发布吗?

nginx的当前状态复制如下:

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;
        }
Run Code Online (Sandbox Code Playgroud)

编辑

我想知道我是否需要使用Jetty.在这个设置中他只使用戒指,这似乎超级容易?使用码头可以获得什么?


Fer*_*o. 14

如何配置nginx以使用java服务器.在示例中使用了Jetty.

编辑/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;
  }
}
Run Code Online (Sandbox Code Playgroud)

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

/sbin/iptables -A INPUT -p tcp -i eth0 --dport 8080 -j REJECT --reject-with tcp-reset
Run Code Online (Sandbox Code Playgroud)

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

<?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>
Run Code Online (Sandbox Code Playgroud)

这将导致Jetty侦听localhost:8080和nginx以将请求从domain.com:80重定向到Jetty服务器.