java - jetty-runner/stats 端点只能在本地主机上使用,如何打开网络?

标签 java jetty

来自 the jetty-runner documentation --stats 标志将允许在 http://localhost/stats 下显示统计信息。但是 AFAICT 不适用于任何其他界面,而且我没有看到配置它的方法。

有没有办法打开/stats到网络?

详情如下:

启动 jetty,运行 grobid war,打开“stats”并取消密码,没有任何 --host 标志

$ java -jar jetty-runner-9.2.3.v20140905.jar  --stats unsecure grobid-service-0.2.10.war  &
[10] 29549
$ 2014-11-07 09:07:31.255:INFO::main: Logging initialized @47ms
2014-11-07 09:07:31.261:INFO:oejr.Runner:main: Runner
2014-11-07 09:07:31.383:INFO:oejs.Server:main: jetty-9.2.3.v20140905
2014-11-07 09:07:31.416:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@6981170d{/stats,null,AVAILABLE}
Nov 07, 2014 9:07:33 AM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  org.grobid.service
Nov 07, 2014 9:07:33 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class org.grobid.service.GrobidRestService
Nov 07, 2014 9:07:33 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Nov 07, 2014 9:07:33 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM'
2014-11-07 09:07:35.160:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1a108c98{/,file:/tmp/jetty-0.0.0.0-8080-grobid-service-0.2.10.war-_-any-6704428208347840300.dir/webapp/,AVAILABLE}{file:/home/kevin/temp/xx/grobid-service-0.2.10.war}
2014-11-07 09:07:35.161:WARN:oejsh.RequestLogHandler:main: !RequestLog
2014-11-07 09:07:35.180:INFO:oejs.ServerConnector:main: Started ServerConnector@10a54c39{HTTP/1.1}{0.0.0.0:8080}
2014-11-07 09:07:35.180:INFO:oejs.Server:main: Started @3998ms

我可以从外网接口(interface)请求grobid服务,没问题

$ wget -qS 'http://192.168.122.171:8080' -O - | head -5
  HTTP/1.1 200 OK
  Date: Fri, 07 Nov 2014 17:10:19 GMT
  Accept-Ranges: bytes
  Content-Type: text/html
  Last-Modified: Tue, 04 Nov 2014 21:03:04 GMT
  Content-Length: 7772
  Server: Jetty(9.2.3.v20140905)
<!DOCTYPE XHTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Grobid Web Application</title>

但是“/stats/”是该接口(interface)上的 503 服务不可用

$ wget -qS 'http://192.168.122.171:8080/stats/' -O - | head -5
  HTTP/1.1 503 Service Unavailable
  Date: Fri, 07 Nov 2014 17:11:41 GMT
  Cache-Control: must-revalidate,no-cache,no-store
  Content-Type: text/html; charset=ISO-8859-1
  Content-Length: 294
  Server: Jetty(9.2.3.v20140905)

尽管“/stats/”在本地主机上可用

$ wget -qS 'http://127.0.0.1:8080/stats/' -O - | head -5
  HTTP/1.1 200 OK
  Date: Fri, 07 Nov 2014 17:15:30 GMT
  Content-Type: text/html; charset=ISO-8859-1
  Content-Length: 1342
  Server: Jetty(9.2.3.v20140905)
<h1>Statistics:</h1>
Statistics gathering started 9185ms ago<br />
<h2>Requests:</h2>
Total requests: 3<br />
Active requests: 1<br />

为了响应下面 Joakim Erdfelt 的建议,像这样添加 --host 0.0.0.0 或 --host 192.168.122.171

java -jar jetty-runner-9.2.3.v20140905.jar --host 192.168.122.171 --stats unsecure grobid-service-0.2.10.war  &

仍然会导致 503-Service Unavailable。我知道 --host 192.168.122.171一些效果,因为有了那个标志,/ 的工作页面在 查询时不可用127.0.0.1.

最佳答案

如果有人遇到与@KevinG 相同的问题,这是我的解决方案,因为我发现这个主题试图解决相同的问题,经过一段时间的思考,我找到了克服限制的方法,统计数据可以是仅从运行 jetty-runner 的机器/服务器本地调用。

首先在运行 jetty-runner 的同一台服务器/机器上设置 nginx。确保在 nginx 配置中使用代理转发将所有流量转发到 jetty-runner (localhost:8080)。默认情况下,您的 nginx 应该监听端口 80。打开 http://localhost:80从您的主机服务器/机器/本地 pc 和 nginx 会将您的请求转发给 jetty-runner 并返回回复。同样适用于/stats/。打开http://localhost:80/stats/在您的主机/本地电脑上,您将到达 jetty-runner 的统计页面。

nginx 配置:

server {

listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;

## default location ##
location / {
  access_log off;
  proxy_pass http://localhost:8080;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

关于java - jetty-runner/stats 端点只能在本地主机上使用,如何打开网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26791966/

相关文章:

java - 从 Webapp 并行调用不同的 Web 服务

java - 为什么使用 boolean 数组需要这么长的时间?

java - Apache Ignite 的未知异常

java - 空 HttpServletRequest

java - 最简单、最轻量级的 Java Web 服务引擎?

java - SpringMVC RestEasy Integration Bean 未注入(inject)到 Controller 类中

java - Java中的前后端字符串

java - 通过反射运行 jetty Web 服务

java - Jetty 错误地报告状态 isRunning() 和 isFailed()

jetty - 如何防止 Jetty 显示上下文相关信息