Closed
Description
When Magento runs using the sandwich hosting set up (nginx-Varnish-nginx), and the backend nginx run on a not standard port (80 nor 443), the base URL is detected wrong in pub/errors/processor.hp
Preconditions
- Magento 2.1.7
- nginx as the SSL offloader on 80, 443 ports
- Varnish used for FPC
- nginx as the backend for Varnish listening to not standard port (for example 8081)
- PHP-FPM runs Magento
- Production mode
Steps to reproduce
- Open any media resource that does not exist and is not allowed in
var/resource_config.json
Expected result
- Magento's 404 page should be displayed in the browser with a link to configured skin CSS.
- Base in the HTML code should be generated based on the requested host, for example:
<base href="https://domain.com/errors/default/" />
Actual result
- Magento's 404 page should be displayed in the browser with a link to configured skin CSS.
- Base in the HTML code is generated based on the requested host AND
$_SERVER['SERVER_PORT']
, for example:
<base href="https://domain.com:8081/errors/default/" />
- No static assets with relative path can be loaded due to the faulty base
The logic in processor.php
should be similar to one in //vendor/zendframework/zend-http/src/PhpEnvironment/Request.php
:
- Try to use HTTP_HOST header
- If the above is not available, the host is
$_SERVER['SERVER_NAME']
:$_SERVER['SERVER_PORT']
At this moment also in 2.3-develop branch the server port is always concatenated:
public function getHostUrl()
{
/**
* Define server http host
*/
if (!empty($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} elseif (!empty($_SERVER['SERVER_NAME'])) {
$host = $_SERVER['SERVER_NAME'];
} else {
$host = 'localhost';
}
$isSecure = (!empty($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] != 'off');
$url = ($isSecure ? 'https://' : 'http://') . $host;
// ------> should not be the case if the $host is assigned
// ------> from $_SERVER['HTTP_HOST']
if (!empty($_SERVER['SERVER_PORT']) && !in_array($_SERVER['SERVER_PORT'], [80, 433])
&& !preg_match('/.*?\:[0-9]+$/', $url)
) {
$url .= ':' . $_SERVER['SERVER_PORT'];
}
return $url;
}
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release