Applicable to:
- Plesk for Linux
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:
CONFIG_TEXT: 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:
CONFIG_TEXT: 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.inc
via any text editor and add the following lines to it:CONFIG_TEXT: 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-server
andsw-engine
to 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:8443
in 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:
CONFIG_TEXT: https://example.com:8443 => https://hostname.com:8443
Perform the following stepsNote: 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.inc
via any text editor and add the following lines to it:CONFIG_TEXT: 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:CONFIG_TEXT: if ($host !~ 'hostname.com|127.0.0.1|localhost'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
} -
Restart services
sw-cp-server
andsw-engine
to 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:8443
in 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.
-
Comments
0 comments
Please sign in to leave a comment.