简体   繁体   English

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

[英]How do I configure nginx as proxy to jetty?

I've been trying to set up nginx as proxy to jetty. 我一直在尝试将nginx设置为jetty的代理。 I want to do something as explained in this answer but for Jetty not ring. 我想做一些像这个答案中解释的但是Jetty没有响。

I've created a .war and I placed it in ~/jetty/jetty-dist/webapps/web_test-0.1.0-SNAPSHOT-standalone.war 我创建了一个.war ,我将它放在~/jetty/jetty-dist/webapps/web_test-0.1.0-SNAPSHOT-standalone.war

Say, I want to use the domain example.com with ip address 198.51.100.0. 说,我想使用域名example.com与IP地址198.51.100.0。

I've also copied /etc/nginx/sites-available/default into the file example.com and I have it in the same directory. 我还将/etc/nginx/sites-available/default复制到example.com文件中,并将它放在同一目录中。

Can you help me configure nginx as proxy to jetty in my case? 在我的情况下,你能帮我配置nginx作为jetty的代理吗? I know there are many references online about how to do this but they are all different and I got confused. 我知道网上有很多关于如何做到这一点的参考资料,但它们都不同,我感到困惑。

What specific changes do I need to make in nginx? 我需要在nginx中进行哪些具体更改? What changes do I need to make in jetty.xml? 我需要在jetty.xml中进行哪些更改? Do I need to make any other changes? 我是否需要进行任何其他更改? Will my app be served at example.com/index.html? 我的应用会在example.com/index.html上发布吗?

Current state of nginx is copied below: 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;
        }

EDIT 编辑

I was wondering if I need to use Jetty at all. 我想知道我是否需要使用Jetty。 In this setup he just uses ring, which seems super easy? 这个设置中他只使用戒指,这似乎超级容易? What do I gain by using jetty? 使用码头可以获得什么?


How to configure nginx to work with a java server. 如何配置nginx以使用java服务器。 In the example Jetty is used. 在示例中使用了Jetty。

Edit /etc/nginx/sites-available/hostname : 编辑/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;
  }
}

Consider disabling external access to port 8080: 考虑禁用对端口8080的外部访问:

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

An example Jetty configuration ( jetty.xml ) might resemble: 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>

This will cause Jetty to listen on localhost:8080 and nginx to redirect requests from domain.com:80 to the Jetty server. 这将导致Jetty侦听localhost:8080和nginx以将请求从domain.com:80重定向到Jetty服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何运行nginx作为码头的代理? - How do I run nginx as proxy to jetty? Nginx 代理:如何配置 nginx 以便 Jersey 2 (JAX-RS 2) 仍然可以正确地与其中的其他 URL 部分交互? - Nginx proxy: How do I configure nginx so that Jersey 2 (JAX-RS 2) still can interact with additional URL parts in it properly? 如何配置嵌入式jetty服务器以记录所有请求? - How do I configure embedded jetty server to log all requests? 如何配置嵌入式Jetty服务器以将NCSARequestLog打印到STDOUT - How do I configure embedded Jetty server to print NCSARequestLog to STDOUT 如何配置apache httpcore 4以使用代理? - How do I configure apache httpcore 4 to use a proxy? 如何以编程方式配置我的Jetty请求处理程序以处理自定义HTTP方法 - How do I programatically configure my Jetty Request Handler to Handle custom HTTP methods 使用spring时,如何配置jetty通过maven运行? - How do I configure jetty to run via maven when using spring? 如何将嵌入式码头配置为使用可执行 jar 中的战争文件作为资源 - How do I configure embedded jetty to used war file in executable jar as resource 与Spark Framework一起使用时,如何配置Jetty以允许更大的表单 - How do I configure Jetty to allow larger forms when used with Spark Framework 如何配置Jetty Handlers? - How to configure Jetty Handlers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM