Backport some code from Passenger Enterprise

[ci:skip]