• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

http to https redirect (12.08 / CentOS 7)

maclenin

New Pleskian
[PLESK VERSION SHOULD READ 12.0.18]

I would like to add a return statement to nginx_ip_default.conf, as shown, to redirect http traffic to https:
Code:
server {
listen 12.34.56.78:80 default_server;
server_name domain.com;
server_name www.domain.com;
server_name ipv4.domain.com;
return 301 https://$host$request_uri;
[...]
}
What is the proper method for incorporating this "redirect"?

The top few lines of the nginx_ip_default.conf file are a bit intimidating (when opened to edit):

#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

I am running an apache / nginx environment. Do I need to incorporate a redirect within apache, as well?

Thanks, Spasibo, Danke for any guidance!

P.S. I think the http://ubuntuforums.org/ design is the best in the business....
 
Last edited:
Hi maclenin,

please be aware, that the Plesk webserver templates already include such a rewrite directive for apache and nginx, in case of SSL - usage for the domain/subdomain. You will have a double entry, when you add another one.

If you still insist to add a further https - directive for apache and/or nginx to your domain specific configuration files, please use the Plesk Control Panel:

Websites & Domains > YOUR_DOMAIN.COM > Web Server Settings ( "Additional apache directives" and "Additional nginx directives" )

... but please be aware, that this might cause redirection failures with most browsers ( "too many redirects" ).​
 
UFHH01!

Thank you for the reply. I want to follow best practices, here - I am not interested in adding more directives than are required.

Can you pass along some guidance as to how I would "wake" those already-included (apache and nginx) directives?

EDIT: Upon cursory glance of a few template files and nginx_ip_default.conf, I cannot find any of the directives, which you mention should already be in place.

Thanks for any clarification!
 
Last edited:
Hi maclenin,

For Debian/Ubuntu:

apache:
Go to : /etc/apache2/plesk.conf.d/ip_default/

You will see symlinks to the depending domain - specific apache - configuration files, located at "/var/www/vhosts/system/YOUR_DOMAIN.COM/conf/httpd_ip_default.conf"

Code:
...
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{HTTP_HOST} ^YOUR_DOMAIN.COM$ [NC]
            RewriteRule ^(.*)$ https://www.YOUR_DOMAIN.COM$1 [L,R=301]
        </IfModule>
...
nginx:
Go to : /etc/nginx/plesk.conf.d/ip_default/

You will see symlinks to the depending domain - specific apache - configuration files, located at "/var/www/vhosts/system/YOUR_DOMAIN.COM/conf/nginx_ip_default.conf"

Code:
...
    if ($host ~* ^YOUR_DOMAIN.COM$) {
        rewrite ^(.*)$ https://www.YOUR_DOMAIN.COM$1 permanent;
    }
...

The depending deafult Plesk templates which define the redirects are "/opt/psa/admin/conf/templates/default/domain/service/seoSafeRedirects.php" ( apache ) and "/opt/psa/admin/conf/templates/default/domain/service/nginxSeoSafeRedirects.php" ( nginx ).


Can you pass along some guidance as to how I would "wake" those already-included (apache and nginx) directives?
You always have the choice to choose the depending certificate for a domain/subdomain over the Plesk Control Panel at: Home > Domains > YOUR_DOMAIN.COM > Hosting settings ... Security / SSL support

If you experience issues, please select "Not selected", save the options and re-select your desired SSL - certificate again, in order to solve issues. Plesk should rebuild your domain specific configuration files, based on your settings on each saving procedure.


You could as well, check your settings and IF you are sure, all is set as desired, use the command:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
or
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain YOUR_DOMAIN.COM
 
UFHH01!

I hear you - and thank you for the roadmap - through which I think I've been able to identify the key files and directives. The point at which I lose my way - is "how" to deploy the directive?

I've found the template: nginxSeoSafeRedirects.php
I've located the directives within the template
I've found the conf file: nginx_ip_default.conf
The nginx_ip_default.conf file shows no "redirect customization" - thought it appears tailored to my domain and recent SSL activation.

I feel like I have to choose and manually activate one of the redirect directives from the .php template - but I do not know which and how to make this happen.

I am holding all the pieces - I just don't know how to put them together.

Thanks, again, for helping with this.
 
...to complement my earlier reply - I'll refer to:

http://talk.plesk.com/threads/nginx-redirect-to-https.334549/

Because I chose "none" in my preferred-domain hosting settings...
This depends on your "Hosting settings" for that domain, where you can choose the options: "none", "example.com" or "www.example.com". If you choose "example.com" or "www.example.com", then Plesk will automatically add the redirects to your configuration files for the specific domain. If you now add an additional redirect, all browsers will complain about "too many redirects".
...Plesk might not have automatically added the (https or any) redirects.

Therefore, I might want to try adding...
Code:
if ($ssl_protocol = "") {rewrite ^   https://$server_name$request_uri? permanent;}
...to Webserver Settings / Additional nginx directives...and then count to 10?

However, if I were to select a preferred domain (www or non-www) - this choice should automatically generate a redirect - as the preference is, in essence, a redirect? If so, should the "preferred domain" http redirect morph into an https redirect, after ssl is installed?

Would my added redirect directive become redundant, if I were to declare a preference?

Thanks for any additional wisdom.
 
Back
Top