码迷,mamicode.com
首页 > 其他好文 > 详细

JETTY+NGINX

时间:2018-09-20 21:28:09      阅读:432      评论:0      收藏:0      [点我收藏+]

标签:route   coding   添加   txt   .so   The   off   eclipse   ini   

一、Jetty搭建

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

[root@localhost home]# tar -xvf jetty.tar 

[root@localhost home]# ls
jetty  jetty.tar  

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

 root@localhost 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 创建映射文件

[root@localhost channel-openapi-reroute]# pwd
/data/channel-openapi-reroute

[root@localhost webapps]# ls

channel-openapi-reroute.xml  README.TXT

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

 

  1.  
    [root@localhost 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

[root@localhost jetty]# ./bin/jetty.sh start

 

 

二、Nginx中配置文件

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

[root@localhost vhost]# pwd
/usr/local/nginx/conf/vhost
[root@localhost 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重新加载

[root@localhost vhost]# service nginx reload

3.客户端添加host(C:\Windows\System32\drivers\etc\hosts),请求java服务

192.168.13.199  www.openapi.net

 

备注:

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

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

3.一个jetty跑一个java服务

JETTY+NGINX

标签:route   coding   添加   txt   .so   The   off   eclipse   ini   

原文地址:https://www.cnblogs.com/UUUz/p/9683093.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!