Solr and WSL

Recently, I was trying to use Apache Solr on my WSL install of Ubuntu 20.04. Following the docs, I could download and start Solr, but visiting 127.0.0.1:8983/solr/ from a browser in Windows gave me an "unable to connect" error. The solr logs showed no errors, and the access log didn't even show an incoming request. curling the same URL from inside WSL gave a normal response.

It turned out WSL was not opening the port to localhost on Windows. To fix it, specify the command line argument -Dsolr.jetty.host. For example, to listen on all interfaces:

solr-9.0.0$ bin/solr start -h 0.0.0.0 -Dsolr.jetty.host=0.0.0.0

If you prefer to not listen on all interfaces, you can also use the internal WSL IP address, in the 172. range. This can be found in WSL in the result of ip addr.

To verify it worked, look for 0.0.0.0 (or the IP/hostname you specified) in the Solr log with something like, o.e.j.s.AbstractConnector Started ServerConnector@0a1b2c3d{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:8983}. You can also check Resource Monitor in Windows, in the Network tab, under "Listening Ports". Scroll down to 8983 and you should see your process.

Neither the Solr 9 getting started documentation nor the command line reference mention this flag. They do list the -h flag for setting a hostname, but it doesn't appear to be sufficient? I ran into the issue because I was using WSL, but surely there are Solr deploys in the wild that need to set a hostname. Anyone with inside information feel free to update me.

Hope it saves you some time.

Written for:

  • Windows 10
  • Ubuntu 20.04 on WSL 2
  • Solr 9