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 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 For example, to listen on all interfaces:

solr-9.0.0$ bin/solr start -h

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 (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)}{}. 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