KB Issue
IIS ARR Web Server gives 502 bad gateway error.
Issue Details
502 - Web server received an invalid response while acting as a gateway or proxy server.
There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (acting as a gateway or proxy) contacted the upstream content server, it received an invalid response.
Recreate Issue
SSL Certificates are not the same throughout the IIS Server Farm.
When building an [ARR Server Farm], all machines must match; if not, you will receive the [502 Bad Gateway error]. The [SSL Certificate] is just one of many different issues if the configurations are not identical.
Resolve Issue
Ensure all [SSL Certificates] are the same on all machines throughout the [IIS Server Farm].
These include the [ARR] (Application Request Routing) and [IIS Servers].
To ensure they are the same, it is best to export the most recent [SSL Web Server
Certificate
] from the known good server and copy and install this certificate
throughout the [IIS Server farm].


All codes are done in PowerShell.
[PowerShell - SSL key exists]
CFFCS | CarrzSynEdit: | PS (PowerShell)
:: First, we need to find out if the SSL key exists
dir cert:\localmachine\webhosting | Where-Object { $ .hasPrivateKey }

[PowerShell - Export Certificate]
CFFCS | CarrzSynEdit: | PS (PowerShell)
:: If it does, then we launch this script
$mypwd = ConvertTo-SecureString -String "PASSWORD-GOES-HERE" -Force -AsPlainText
Get-ChildItem -Path cert:\LocalMachine\webhosting | Export-PfxCertificate -FilePath G:\SSL\Most-Recent-SSL-Cert.pfx -Password $mypwd

[PowerShell - Copy Certificate to another Server]
CFFCS | CarrzSynEdit: | PS (PowerShell)
:: Copy the known-good IIS Cert from the server to the server to install on.
Copy-Item -Path '\\WebServer-Name\G\SSL\certs\Most-Recent-SSL-Cert.pfx' -Destination \\Webc01\g\SSL\Most-Recent-SSL-Cert.pfx

[PowerShell - Import Certificate to the Certificate Store]
CFFCS | CarrzSynEdit: | PS (PowerShell)
:: Import to the Server
$pwd = ConvertTo-SecureString -String "PASSWORD-GOES-HERE" -Force -AsPlainText
Import-PfxCertificate -FilePath G:\SSL\Most-Recent-SSL-Cert.pfx Cert:\LocalMachine\WebHosting -Password $pwd