Page 1 of 1

How do I redirect all traffic to the https:// domain?

Posted: Thu Jun 22, 2017 10:18 am
by Spythe
Hey guys,

I've setup Vesta and added SSL support for all domains with Let's Encrypt. When manually typing https://domain.com it'll show the site with SSL turned on, but when I just type domain.com it'll always navigate to the non-SSL http:// variant.

How do I make all traffic, per domain or all domains all together (since all domains will have SSL) go automatically to https://domain.com ?

I already googled and saw lots of suggestions, including server {} blocks, which I pasted within the http {} part in the /etc/nginx/nginx.conf file and restarted the server, but that didn't change a thing..

Re: How do I redirect all traffic to the https:// domain?

Posted: Fri Jun 23, 2017 12:44 am
by shanjie

Re: How do I redirect all traffic to the https:// domain?

Posted: Thu Dec 31, 2020 11:56 am
by castris
Post is older but doc is actual.
How to force https/SSL on a domain
1. Install custom nginx template

Code: Select all

cd /usr/local/vesta/data/templates/web
wget http://c.vestacp.com/0.9.8/rhel/force-https/nginx.tar.gz
tar -xzvf nginx.tar.gz
rm -f nginx.tar.gz
3. Create new package or set force-https as nginx template in the existing package
4. Add new user and assing him package with force-https template
5. Add new domain with SSL certificate and check the result
Well...

After step 2, there're in /usr/local/vesta/data/templates/web/nginx/ two new files, force-https.stpl and force-https.tpl

Step 3 create a package or force-https no work using any template named force-https

Any template named force-htpps on VestaCP interface, in new template or on domain for apply new template.

What is wrong?




I'm using vestaCp 0.9.8 Release 26

Re: How do I redirect all traffic to the https:// domain?

Posted: Wed Jul 19, 2023 3:47 pm
by nehavilash
Hi,

You can configure the server block to redirect all traffic to the HTTPS version of your domains.
Here's how:
1. Go to Nginx configuration  '/etc/nginx/conf.d/'.
2. Create a new configuration file for redirection.
3. Edit  https-redirect.conf and paste the below code.

Code: Select all

server {
    listen 80;
    server_name domain.com www.domain.com;

    location / {
        return 301 https://domain.com$request_uri;
    }
}
4, Save it then test the Nginx configuration.

Code: Select all

nginx -t
5. If everything is correct, you should see a message 
Finlay restart to apply changes.

Code: Select all

systemctl reload nginx
Manually check individual urls or use any online tool such as this https://redirectchecker.com/ to get a detailed redirection chain and its status code.
I hope the above steps help.

Re: How do I redirect all traffic to the https:// domain?

Posted: Tue Sep 26, 2023 4:26 am
by slipchant
Wow, This guide is very useful to me.