XF 1.5 Stop appending port to URLs

Parsnip

Active member
I'm running XF on a non-standard port behind a reverse proxy.

How can I stop XF from detecting the server port and appending it to all URLs?

Visitors should be oblivious to the server configuration and just see the domain name as normal with no appended port.
 
It looks like I need to override the base url somewhere so that $requestPaths.fullBasePath doesn't contain the port.

Code:
<base href="{$requestPaths.fullBasePath}" />
<script><xen:comment>/* Chrome bug and for Google cache */</xen:comment>
    var _b = document.getElementsByTagName('base')[0], _bH = "{xen:jsescape $requestPaths.fullBasePath}";
    if (_b && _b.href != _bH) _b.href = _bH;
</script>

Maybe I can manually edit this in the PAGE_CONTAINER template, but whether there's a better way I don't know.
 
You would likely need to override $_SERVER['SERVER_PORT'] in config.php to force it to what the correct one is (the version seen by the reverse proxy).
 
Changing the below code getRequestPaths in library/XenForo/Application.php also fixes it, but I'd rather not do that.

How can I override the port in config.php? I can't find any mention of an option for that in the manual.

Code:
$host = $request->getServer('HTTP_HOST');
if (!$host)
{
        $host = $request->getServer('SERVER_NAME');
        $serverPort = intval($request->getServer('SERVER_PORT'));
        if ($serverPort && $serverPort != 80 && $serverPort != 443)
        {
                $host .= ':' . $serverPort;
        }
}

Change to just..

Code:
$host = $request->getServer('SERVER_NAME');
 
You need to set $_SERVER['SERVER_PORT'] to what the "correct" port is (what the browser is connecting to the proxy with).

You'd just set that variable directly in config.php -- it's not a XenForo option. You're just effectively changing what we/PHP "see" as the port that was used.
 
Top Bottom