How do you configure jetty to allow access from an

2019-04-16 15:06发布

问题:

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);