灰熊+泽西岛仅在Localhost上收听

编程入门 行业动态 更新时间:2024-10-25 11:21:58
本文介绍了灰熊+泽西岛仅在Localhost上收听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用带有Grizzly嵌入式版本的Jersey,我只想在本地主机上绑定/监听.我正在使用带有create调用的GrizzlyWebContainerFactory创建ThreadSelector:

I'm using Jersey with an embedded version of Grizzly and I'd like to bind/listen on localhost ONLY. I'm creating the ThreadSelector using the GrizzlyWebContainerFactory with the create call:

threadSelector = GrizzlyWebContainerFactory.create("127.0.0.1:8080/", initParams);

这可行,但是我仍然可以从外部计算机上访问服务器.我如何才能将其绑定到/仅在本地主机上监听?

This works, but I'm still able to hit the server from an external machine. How can I get it to bind to/listen on ONLY localhost?

这是用于配置的东西,所以我不希望有任何其他东西能够连接到该服务器.

This is for configuration stuff, so I don't want anything off box to be able to connect to this server.

推荐答案

我能够使用泽西2.3.1中带有嵌入式版本Grizzly的主机名localhost来做到这一点:

I was able to do this using the hostname localhost in Jersey 2.3.1 with an embedded version of Grizzly:

import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; // ... GrizzlyHttpServerFactory.createHttpServer( URI.create("localhost:9580/my-app/") );

测试结果为:

> curl -I myhost:9580/my-app curl: (7) couldn't connect to host

当使用URI "0.0.0.0:9580/my-app/"或"myhost:9580/my-app/"启动Grizzly服务器时,我可以使用

Whereas when starting the Grizzly server with the URIs "0.0.0.0:9580/my-app/", or "myhost:9580/my-app/" I am be able to hit it with

> curl -I myhost:9580/my-app HTTP/1.1 200 Not Found ...

这是一张表格,其中列出了使用GrizzlyHttpServerFactory时哪些主机使用哪些URL.据我所知,这里没有什么惊奇之处:

Here's a table of which hosts work with which URLs when using GrizzlyHttpServerFactory. No surprises here, as far as I understand:

# For 0.0.0.0:9575/my-app | Works? curl -I 0.0.0.0:9575/my-app | Yes curl -I 127.0.0.1:9575/my-app | Yes curl -I localhost:9575/my-app | Yes curl -I myhost:9575/my-app | Yes | # For 127.0.0.1:9575/my-app | # For localhost:9575/my-app | curl -I 0.0.0.0:9575/my-app | Yes curl -I 127.0.0.1:9575/my-app | Yes curl -I localhost:9575/my-app | Yes curl -I myhost:9575/my-app | No | # For myhost:9585/my-app | curl -I 0.0.0.0:9585/my-app | No curl -I 127.0.0.1:9585/my-app | No curl -I localhost:9575/my-app | No curl -I myhost:9585/my-app | Yes

更多推荐

灰熊+泽西岛仅在Localhost上收听

本文发布于:2023-07-15 01:57:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1108351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:灰熊   泽西   Localhost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!