When you install VestaCP, MyVestaCP, or HestiaCP, they create two config files for Nginx:
- domain.nginx.conf
- domain.nginx.ssl.conf
You need to make changes in both files to redirect all URLs to https with www.
1. domain.nginx.conf
In this file, make the following highlighted changes:
server {
listen ip_address:80;
server_name example.com www.exampl.com;
return 301 https://$host$request_uri;
2. domain.nginx.ssl.conf
In this file, make the following highlighted changes:
server {
listen ip_address:443 ssl http2;
server_name example.com www.example.com;
if ($host = 'example.com'){
return 301 https:/ /www.example.com$request_uri;
}
The URL is redirected to only https without modifying "domain.nginx.ssl.conf". So, if you want both https and www, you need to modify both files.