Rails application is thinking that the request is done to whichever port passenger is running, hence, request.url (both on Rack::Request & ActionDispatch::Request) & url_for only_path: false will use this port in generated url (e.g : http://example.com:4000/path)
The generated url should use the original port.