Maybe it also increase stomach acid production, but my understanding is that the primary problem is that it thins the protective stomach lining.
Ibuprofen is a non-selective inhibitor of the COX enzymes. Inhibiting COX-2 reduces pain and inflammation. Inhibiting COX-1 inhibits stomach lining growth and the clotting process. Pharma has created selective COX-2 inhibitors, but some of those have run into their own problems (blood clots leading to myocardial infarctions in the case of Vioxx patients who weren't also on aspirin, IIRC... though, an increase in MIs would seem to be the natural and obvious side effect of intentionally reducing COX-1 inhibition. IIRC, the increase in MIs was in contrast to the traditional Ibuprofen treatment, not compared to an unmedicated baseline.)
In some ways it's a relief to hear from someone else with that experience (this was 20 years ago for me).
Food also helps but not 100%. IME it does not seem to "soak up" all of the excess acid. Vitamin C is also not 100% but IME more effective than food.
I'm not a frequent or high dose user of NSAIDs, I just seem to have an easily irritated stomach.