Nginx與jetty結合

一、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和文件夾

 

[root@localhost webapps]# vi channel-openapi-reroute.xml 

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

<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test

Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.  By specifying a context in this
directory, additional configuration may be specified and hot deployments
detected.
===================================================================== -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
 <span style="background-color: rgb(255, 102, 102);"> <Set name="contextPath">/</Set>
  <Set name="war">/data/channel-openapi-reroute</Set></span>

</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服務

發佈了38 篇原創文章 · 獲贊 22 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章