Question
How to configure a redirect from the domain name/IP address to the server hostname on port 8443 in Plesk for Linux?
How to set up the following redirects in Plesk:
https://example.com:8443 => https://hostname.com:8443
https://203.0.113.2:8443 => https://hostname.com:8443
where:
"example.com" is any domain hosted on the Plesk server and resolved to it.
"hostname.com" is Plesk server hostname.
"203.0.113.2" is Plesk IP address.
Answer
To configure the redirect from the server IP address to the server hostname:
https://203.0.113.2:8443 => https://hostname.com:8443
Perform the following steps
Connect to the server using SSH.
Create the file
/etc/sw-cp-server/conf.d/z-plesk.inc:# touch /etc/sw-cp-server/conf.d/z-plesk.inc
Open the file
/etc/sw-cp-server/conf.d/z-plesk.incvia any text editor and add the following lines to it:if ($host ~ '203.0.113.2'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
}Note: Replace 203.0.113.2 with the correct Plesk server's IP address, and hostname.com with the real Plesk server's hostname.
Restart services
sw-cp-serverandsw-engineto apply changes:# service sw-cp-server restart && service sw-engine restart
Note: Even after the redirect is set up and Plesk is secured by an SSL certificate, an attempt to access
https://203.0.113.2:8443in a browser will end up with the error regarding the untrusted certificate. It is expected behaviour and happens because the redirect is performed after the certificate check.
To configure the redirect from a domain name to the server hostname:
https://example.com:8443 => https://hostname.com:8443
Perform the following steps
Note: If the domain(s) have HTTP Strict Transport Security (HSTS) enabled, disable it before applying the steps below.
Connect to the server using SSH.
Create the file
/etc/sw-cp-server/conf.d/z-plesk.inc:# touch /etc/sw-cp-server/conf.d/z-plesk.inc
Open the file
/etc/sw-cp-server/conf.d/z-plesk.incvia any text editor and add the following lines to it:if ($host ~ 'example.com'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
}Note: Replace example.com with the correct website that resolves to Plesk server's IP address, and hostname.com with the real Plesk server's hostname
For redirect from all hosted domains names to
https://hostname.com:8443, add the following directives:if ($host !~ 'hostname.com|127.0.0.1|localhost'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
}Restart services
sw-cp-serverandsw-engineto apply changes:# service sw-cp-server restart && service sw-engine restart
Note: Even after the redirect is set up and the website is secured with an SSL certificate, in an attempt to access
https://example.com:8443in a browser will end up with the error regarding the untrusted certificate. It is expected behaviour and happens because the redirect is performed after the certificate check.