您的位置:首页 > 运维架构 > Nginx

Nginx与jetty结合

2015-07-15 16:42 405 查看
一、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服务
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: