how to make jetty server accessible from LAN?

点点圈 提交于 2019-11-27 06:42:32

问题


I am trying to access a web app (deployed in jetty8 on my machine (A)) from another machine (B) on the LAN using 192.168.0.6:8080 (A's IP) but its not working. While I can access apps hosted on AppServ on machine B from A normally using 192.168.0.5 (B's IP).

I can access the app normally on localhost:8080 on machine A.

I can assure that there is no network problem, but jetty is not accessible through the network for some reason. Is there any specific configuration to make accessible through the LAN?

My app is Maven project and I run it from eclipse and settings are in both web.xml and pom.xml.


回答1:


The following answer is for Jetty 8 and older (Jetty 9+ commands and class names are different)

Make sure you check what interfaces you are listening on.

Example (from logs)

2012-08-10 14:52:26.470:INFO:oejs.AbstractConnector:Started SelectChannelConnector@127.0.0.1:8080

That says the server is only listening on 127.0.0.1 (localhost) You can either look at the logs, or just do a quick test, while on machine A. Open a web browser and test both of these URLs

  • http://localhost:8080/
  • http://192.168.0.6:8080/

If it responds on both URLs then you likely have it setup correctly and need to deal with firewall issues. If it works for one, but not the other, then you are only listening on 1 interface.

To have jetty listen on all interfaces, use the special IP 0.0.0.0

$ java -Djetty.host=0.0.0.0 -jar start.jar
2012-08-10 14:53:25.338:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080

At this point, jetty is listening on all interfaces on your machine.

Note: you can also edit etc/jetty.xml and set the host permanently.

      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host">0.0.0.0</Set>
      ...



回答2:


So I hit this and after an afternoon of debugging odd behaviours, I discovered Jetty was only broadcasting itself to IPv6, and skipping IPv4, the v4 port was allocated to another app.

My solution? Jump to another port...



来源:https://stackoverflow.com/questions/11808075/how-to-make-jetty-server-accessible-from-lan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!