NGinx HTTP to HTTPs redirect for subdomain in Plesk

March 5, 2015 2.9k views
Nginx Security Ubuntu


I ve installed Plesk on my Ubuntu 12.04 instance which runs NGinx. I am trying to redirect my subdomain calls to HTTPs. That means any call with http to my subdomain ( should redirect to (

I have followed instructions in the website but they are not working. I could not find the correct file to configure and correct configuration strings.

I am looking for your help to redirect HTTP to HTTPs. What configuration file I should work on and what configuration strings I should add?

Thanks in advance,

3 Answers

Generally, you'll want your Nginx configuration to look something like the below to redirect HTTP to HTTPs:

server {
       listen         80;
       return         301 https://$server_name$request_uri;

server {
       listen         443 ssl;

       # The rest of your normal configuration

The default configuration file is located in /etc/nginx/sites-enabled/default

We might be able to give you more specific instructions if you could give more information like what you already tried or if you can describe exactly what you mean by "not working" (i.e. was there an error message).

  • Thats true configuration but in my case it worked in /etc/nginx/plesk.conf.d/vhosts/ file.

Not sure how plesk handle nginx configuration, can be messy to mess around those files too if plesk overwrites them. but you can try this and add some speed/security to your site.

Open an account at add your domain, and enable strict SSL this will route all your traffic to https even before it reaches your server, is free and add some security and speed to your site.

Now if you find the way via Plesk to avoid files being overwritten, then give it a try, but to be honest is a lot better if you avoid cpanels. One option I can think about it is to create 2 sites, one for http with a redirect (even a header redirect will work), and one for https.

  • My website will be used for insert, update, deletes mostly. I am afraid cloudflare make my transactions slower.

Cloudflare will not make your site slower, if any will be faster, specially if you use spdy, which you should as you already have nginx up and running.

Go check cloudflare's blog, they have good explanations about the SSL and SPDY protocols they offer.

Have another answer? Share your knowledge.