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
-
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 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 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
sw-cp-server
andsw-engine
services 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 the
https://203.0.113.2:8443
in a browser will end up with the error regarding the untrusted certificate. It 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 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 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'){
rewrite ^/(.*)$ https://hostname.com:8443/$1 permanent;
} -
Restart sw-cp-server and sw-engine services 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 the
https://example.com:8443
in a browser will end up with the error regarding the untrusted certificate. It happens because the redirect is performed after the certificate check.
-
Comments
12 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.
I used this method to redirect all panel requests to server hostname, but starting from month ago my Advanced Monitoring not working, when this method is implemented.
Error Advanced monitoring throw is: login.OAuthLogin(NewTransportWithCode)
When rules are removed from this file /etc/sw-cp-server/conf.d/z-plesk.inc, Advanced Monitoring Tool start working again.
I re-installed latest Grafana and Advanced Monitoring Extensions, with updates
1.4.3 (19 June 2021) - Advanced Monitoring Extension
1.2.3 (18 June 2021) - Grafana Extension
Logs:
Hello Milos Bajcetic,
Thank you for bringing our attention to the issue! It was reproduced from our side. When redirecting all hosted domains to https://hostname.com:8443, Advanced Monitoring is not loading graphs. This part of the article has been hidden.
The issue will be checked from our side. If possible, the solution in the article will be updated.
I would prefer to not redirect from ip to the host for security purposes. Is there a way to deny ip address :8443 requests instead? For example:
https://203.0.113.2:8443 => Deny
This sort of works but we still get the SSL warning which you noted. Is there a way to redirect before the certificate check?
Hello Glenn,
For the following scenario: https://example.com:8443 => https://hostname.com:8443, if a regular domain is used, not Plesk technical domain, you may try accessing as http://example.com:8880. The redirect should be performed as expected.
Please sign in to leave a comment.