Demand for refined petroleum products (think gasoline, diesel, and jet fuel) is through the roof these days. Oil refiners can't keep up with demand, which is sending refined-product prices higher. That's enabling refiners to capture wide margins (known as the crack spread) between where they buy crude oil and sell the refined products they produce.

These strong market conditions are a boon for refining companies, with many generating gushing profits. Here are three ways you can get in on the oil refining boom.

The pure plays

The most direct way to invest in the refining sector is to buy shares of an independent oil refiner. Several companies focus on refining, including Marathon Petroleum (MPC 0.51%)Valero, Delek USPBF Energy, and Phillips 66.

Marathon operates the country's largest refining system. That enabled it to cash in on strong refining market conditions in the first quarter.

Marathon's refining margin was $15.31 per barrel, up from $10.16 per barrel in the first quarter of last year. Meanwhile, it processed 2.8 million barrels of crude oil per day, up from 2.6 million barrels in the year-ago period. Those factors helped it to produce $1.4 billion of adjusted earnings before taxes, interest, depreciation, and amortization (EBITDA), a substantial improvement from $23 million in the year-ago period. 

With refining market conditions only improving in the second quarter, Marathon could produce an even bigger earnings gusher. That would give it more cash to repurchase stock. Those repurchases could add more fuel to the share price, which has already surged by nearly 30% this year.

The integrated giants

Another way to invest in refining is to buy shares of an integrated oil company like Chevron, ExxonMobil (XOM 0.26%)BP, and TotalEnergies. These global energy giants operate oil and gas production facilities, midstream pipelines, and oil refineries, enabling them to profit from each stage of the value chain.

Exxon has already said its refining segment will produce a profit gusher in the second quarter. The company reported that rising refining margins would likely add $4.4 billion-$4.6 billion to its refining profits, while the value of its hedges could add another $700 million-$900 million to its bottom line. That's up to $5.5 billion of additional refining profits in the second quarter. 

Those surging refining profits are giving Exxon more cash to return to shareholders, with the oil giant aiming to buy back $30 billion of its stock by the end of next year. Those buybacks could help push its stock price even higher, building on the company's nearly 40% return this year.

Midstream MLPs

A less-direct way to invest in the refining sector is through a master limited partnership (MLP) that supports the flow of crude oil and refined petroleum products. These include Magellan Midstream Partners (MMP), MPLX, PBF Logistics, and Delek Logistics Partners.

Magellan Midstream is an MLP focused on transporting, storing, and distributing refined petroleum products like gasoline and jet fuel. The company operates the country's longest refined petroleum-products pipeline system, with 9,800 miles of pipeline, 54 terminals, and 47 million barrels of storage capacity. It gets about 72% of its revenue from refined products and the other 28% from crude oil services.

These midstream assets generate relatively steady fee-based income for the MLP. That enables it to pay an attractive distribution that currently yields 8.7%. This high yield makes Magellan Midstream a potentially appealing option for those seeking to earn income from the refining sector.

Many ways to cash in on the refining boom

The refining industry is cashing in on robust demand for petroleum products. That's enabling their investors to reap a windfall from surging stock prices and lucrative dividends. With market conditions likely to remain strong due to continued capacity constraints and growing demand, investors still have time to cash in on the refining boom.