Java 码头外部地址



我希望我的服务器(码头)通过网络在特定地址访问。如何将码头服务器配置为使用外部地址,例如:my_address_name.org 或其他内容。

因为默认情况下:

server = new Server(port);
        WebAppContext context = new WebAppContext();
        context.setResourceBase(app_path);
        context.setDescriptor(app_path + "WEB-INF/web.xml");
        context.setConfigurations(new Configuration[] {
                new AnnotationConfiguration(), new WebXmlConfiguration(),
                new WebInfConfiguration(), new TagLibConfiguration(),
                new PlusConfiguration(), new MetaInfConfiguration(),
                new FragmentConfiguration(), new EnvConfiguration() });
        context.setContextPath(context_path);
        context.setParentLoaderPriority(true);
        server.setHandler(context);
        try {
            server.start();
            server.join(); ...

它在本地主机上运行...

此示例将绑定到特定 IP 并侦听端口 9090:

Connector con = new SelectChannelConnector();
con.setHost("192.168.1.20");
con.setPort(9090);
server.addConnector(con);

(如果我记得不错,默认情况下,Jetty 总是绑定到所有 IP 的 (0.0.0.0))。

最新更新