I've been through this as well - sometimes it's worse than others. That said, I'm relatively convinced at this point that it's related to digestive issues. It can feel like a spasm - in which case it may be a pulled intercostal muscle (between the ribs)
or be more a deep sensation - which is more often diagnosed as IBS, or Diverticulitus.
If you've been having symptoms like belching or discomfort that gets worse after eating (even an hour or two later) this may be part of the picture. Definitely worth getting checked out however, especially if you tend toward constipation or other bowel related issues. In the meantime, eat lighter meals - especially at dinnertime - as to heavy a meal late in the day or early evening can make laying down without pain difficult.
I was able to gain improvement once I started having hot water plus lemon with a little honey added in the morning & started taking probiotics to help support the digestive process.