How do you configure jetty to allow access from an external server?

我只是一个虾纸丫 提交于 2019-12-21 22:42:27

问题


I've seen this asked before, with no good answers, how do you configure jetty to allow access from an external server? I've just started messing around with solr and jetty and am using the example jetty instance that comes with solr.

solr is running fine on localhost, and I can query it from sites on the same server. However, I can't access the solr instance from another server. I've googled and read quite a bit in the last few days, but have not been able to discover what's keeping jetty from allowing non localhost access to solr.

Based on what I've read, I have tried added the following line to example/etc/jetty.xml

<Set name="Host">0.0.0.0</Set> 

and still got no external response

then tried

<Set name="Host">x.x.x.x</Set>

where x.x.x.x is my server's IP address and

<Set name="Host">host.domain.com</Set>

where host.domain.com is my server's FQDN

These both resulted in the error

java.net.BindException: Cannot assign requested address

when I started.

The start command I'm using is

sudo java -jar start.jar etc/jetty.xml

You can point me to where I can read on this or spoon feed me, I don't care. I'd just like to get past this hurdle so I can keep learning about setting up and using solr.


回答1:


you should add a file called clientaccesspolicy.xml for cross domain access to your static web files directory:

<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-methods="*" http-request-headers="*">
        <domain uri="http://*"/>
        <domain uri="https://*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

you should set you static directory to jetty using this code:

ResourceHandler staticHandler = new ResourceHandler();
staticHandler.setResourceBase("static/dir");
handlers.addHandler(staticHandler);


来源:https://stackoverflow.com/questions/9958329/how-do-you-configure-jetty-to-allow-access-from-an-external-server

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