JETTY+NGINX

Posted 丶柚子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JETTY+NGINX相关的知识,希望对你有一定的参考价值。

一、Jetty搭建

1)上传jetty.tar,并且解压(支持war和文件夹)

[[email protected] home]# tar -xvf jetty.tar 

[[email protected] home]# ls
jetty  jetty.tar  

2)修改jetty-start.d对应程度的端口

 [email protected] start.d]# vi http.ini 
#
# Initialize module http
#
--module=http
## HTTP Connector Configuration
# HTTP port to listen on
jetty.port=8081
# HTTP idle timeout in milliseconds
http.timeout=30000
# HTTP Socket.soLingerTime in seconds. (-1 to disable)
# http.soLingerTime=-1

3)Jetty-webapps 创建映射文件

[[email protected] channel-openapi-reroute]# pwd
/data/channel-openapi-reroute

[[email protected] webapps]# ls

channel-openapi-reroute.xml  README.TXT

[[email protected] webapps]# vi channel-openapi-reroute.xml (支持war和文件夹)

 

  1.  
    [[email protected] webapps]# vi channel-openapi-reroute.xml
  2.  
     
  3.  
    <?xml version="1.0" encoding="UTF-8"?>
  4.  
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
  5.  
     
  6.  
    <!-- ==================================================================
  7.  
    Configure and deploy the test web application in $(jetty.home)/webapps/test
  8.  
     
  9.  
    Note. If this file did not exist or used a context path other that /test
  10.  
    then the default configuration of jetty.xml would discover the test
  11.  
    webapplication with a WebAppDeployer. By specifying a context in this
  12.  
    directory, additional configuration may be specified and hot deployments
  13.  
    detected.
  14.  
    ===================================================================== -->
  15.  
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
  16.  
    <span style=""> <Set name="contextPath">/</Set>
  17.  
    <Set name="war">/data/channel-openapi-reroute</Set></span>
  18.  
     
  19.  
    </Configure>

4)启动jetty

[[email protected] jetty]# ./bin/jetty.sh start

 

 

二、nginx中配置文件

1.在vhost下面创建一个www.openapi.net.conf 文件

[[email protected] vhost]# pwd
/usr/local/nginx/conf/vhost
[[email protected] vhost]# vi www.openapi.net.conf 

server {
        listen      80;
        server_name www.openapi.net;


        access_log  /data/logs/channel-openapi-reroute/openapi_access.log  access;
        error_log   /data/logs/channel-openapi-reroute/openapi_error.log  crit;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                    root   /usr/local/nginx/html;
        }


        location /api {
            proxy_pass      http://127.0.0.1:8081;
            proxy_redirect  off;
            proxy_set_header        Host    $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

2.Nginx重新加载

[[email protected] vhost]# service nginx reload

3.客户端添加host(C:WindowsSystem32driversetchosts),请求java服务

192.168.13.199  www.openapi.net

 

备注:

1.Nginx映射的端口与Jetty配置的端口要一致

2.Ngin的配置文件URL命名要与接口文档一致(否则请求失败)

3.一个jetty跑一个java服务






































以上是关于JETTY+NGINX的主要内容,如果未能解决你的问题,请参考以下文章

NginxNginx配置REWRITE隐藏index.php

NginxNginx配置文件解析

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作

NginxNginx基础操作