Applicable to:
- Plesk for Linux
Question
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
-
For the redirect from 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 via SSH.
-
Create the
/etc/sw-cp-server/conf.d/z-plesk.inc
file:# touch /etc/sw-cp-server/conf.d/z-plesk.inc
-
Open the
/etc/sw-cp-server/conf.d/z-plesk.inc
file via any text editor and add the following rows to it:Change "203.0.113.2" to the correct Plesk IP address.
Change "hostname.com" to the correct Plesk server hostname.CONFIG_TEXT: if ($host ~ '203.0.113.2'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
} -
Restart
sw-cp-server
andsw-engine
services:# service sw-cp-server restart && service sw-engine restart
Note: even after redirect is set up and Plesk is secued by a certificate, in an attempt to open the
https://203.0.113.2:8443
URL, the error regarding the untrusted certificate appears. It happens because the redirect is performed after the certificate check.
-
- For the redirect from a domain name to hostname
CONFIG_TEXT: https://example.com:8443 => https://hostname.com:8443
Perform the following steps- Connect to the server via SSH
- Create the /etc/sw-cp-server/conf.d/z-plesk.inc file:
# touch /etc/sw-cp-server/conf.d/z-plesk.inc
-
Open the
/etc/sw-cp-server/conf.d/z-plesk.inc
file via any text editor and add the following rows to it:Change "example.com" to the correct website resolved to Plesk server.
Change "hostname.com" to the correct Plesk server hostname.CONFIG_TEXT: if ($host ~ 'example.com'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
}For redirect from all hosted domains names to https://hostname.com:8443, add the following directives:
CONFIG_TEXT: if ($host !~ 'hostname.com'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
} -
Restart sw-cp-server and sw-engine services:
# service sw-cp-server restart && service sw-engine restart
Note: even after the redirect is set up and the website is secured by a certificate, in an attempt to open the https://example.com:8443 URL, the error regarding the untrusted certificate appears before the redirect is performed. It happens because the redirect is performed after the certificate check only on the https://example.com:8443 website.
Comments
7 comments
Hi Nikita,
thx for that tutorial. It works for me, but now I have the problem that the Plesk Migrator throws this error:
Failed to check Plesk API connection to target Plesk server: HTTP request to 'https://1.2.3.4:8443/enterprise/control/agent.php' failed with 301 code. When I empty the z-plesk.inc file everything works as expected.
I've tried different solutions like that, but all didn't work (and it's the first time I'm working with nginx config files:
set $redir 1;
if ($host ~ 'example.com'){ set $redir 0; }
if ($host ~ '1.2.3.4'){ set $redir 0; }
if ($redir = 1){ rewrite ^/(.*)$ https://example.com:8443/$1 permanent; }
Thanks for your help.
Hello @Bernhard,
A deeper investigation is required.
Please, consider submitting a request for Plesk support.
The redirect from a domain name to hostname solution at the bottom of the article conflicts with the Advanced Monitoring extension in Plesk. Soon as i removed the above redirect, Advanced Monitoring started working again.
Follwed all the steps but when i have restarted server i got error.
[root@server conf.d]# service sw-cp-server restart && service sw-engine restart
Restarting sw-cp-server (via systemctl): Job for sw-cp-server.service failed because the control process exited with error code. See "systemctl status sw-cp-server.service" and "journalctl -xe" for details.
[FAILED]
[root@server ~]# systemctl status sw-cp-server.service
● sw-cp-server.service - Startup script for Plesk control panel server
Loaded: loaded (/usr/lib/systemd/system/sw-cp-server.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/sw-cp-server.service.d
└─respawn.conf
Active: activating (auto-restart) (Result: exit-code) since Sun 2020-04-26 14:49:39 EEST; 4s ago
Process: 8734 ExecStartPre=/usr/sbin/sw-cp-serverd -q -t (code=exited, status=1/FAILURE)
Apr 26 14:49:39 systemd[1]: Failed to start Startup script for Plesk control panel server.
Apr 26 14:49:39 systemd[1]: Unit sw-cp-server.service entered failed state.
Apr 26 14:49:39 systemd[1]: sw-cp-server.service failed.
any clue?
Hi amarjeet,
What steps did you follow? What Plesk version you use? And what is what you want to do exactly? What kind of redirect?
Hi Amin team
execute
plesk bin admin --enable-access-domain ''
did not work , !!!!!!!!!!!!!!!!!!
please advise
Hello eamon
What was the output of this command?
Was it different from below example?
SUCCESS: Plesk is now accessible over the TCP port 443 (HTTPS) using the domain: default.
Please sign in to leave a comment.