Redirect Domain to Another Domain in Nginx: 5 Easy Ways (CloudPanel Guide)
Redirect domain to another domain in Nginx is a common task when managing websites, especially with CloudPanel. Whether you’re consolidating your web properties or improving SEO, this guide covers the best methods to redirect your domains safely and efficiently.
Why Redirect a Domain in Nginx?
Redirecting domains is essential for ensuring that users reach the right website. For example, if you own example.ca
but want all traffic to go to example.com
, a proper redirect keeps your visitors happy and avoids duplicate content penalties from search engines.
Common reasons include:
- Consolidating multiple domain names
- Switching to a new brand domain
- Ensuring HTTPS usage
- Improving SEO by avoiding duplicate content
Nginx and CloudPanel Overview
CloudPanel uses Nginx as its web server, which means traditional Apache .htaccess
files are not supported. Instead, all redirects must be done in the Nginx configuration files.
This makes redirects faster and more secure but requires you to edit server block files directly.
For beginners, CloudPanel makes managing these configs easier, but you still need to know where and how to add redirects properly.
Step-by-Step Redirect Setup in CloudPanel
Here’s how you can redirect domain to another domain in Nginx using CloudPanel:
- Access your server via SSH. Use tools like Terminal or PuTTY.
- Find your Nginx config file: Usually located at
/home/cloudpanel/htdocs/example.ca/conf/nginx/app.conf
. - Edit the file and add this redirect server block:
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.ca www.example.ca;
ssl_certificate /etc/letsencrypt/live/example.ca/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.ca/privkey.pem;
return 301 https://example.com$request_uri;
}
- Test the config: Run
sudo nginx -t
to ensure no errors. - Reload Nginx: Apply the changes with
sudo systemctl reload nginx
.
This 301 redirect ensures all traffic (HTTP and HTTPS) to example.ca
goes to https://example.com
, preserving SEO value.
For advanced options, read the official Nginx Rewrite Module documentation.
Also, check out our guide on securing your CloudPanel server for additional tips.
SEO Benefits of Redirecting Domains in Nginx
Using a 301 redirect in Nginx correctly helps:
- Pass link equity and rankings to the new domain
- Avoid duplicate content penalties
- Improve user experience by avoiding broken links
- Ensure all URLs are HTTPS and canonical
Search engines like Google recommend 301 redirects for permanent moves. For detailed SEO guidelines, see Google’s official consolidation guide.
FAQ About Redirecting Domains in Nginx
You add a server block listening on the source domain and use return 301 https://targetdomain.com$request_uri;
to redirect all traffic permanently.
CloudPanel uses Nginx, which does not support .htaccess files. Redirects must be configured in the Nginx server configuration files.
Yes, you can configure Nginx to listen on both HTTP and HTTPS and redirect all requests to the HTTPS preferred domain with a 301 redirect.
Yes, a 301 redirect passes most link equity and tells search engines the move is permanent, preserving SEO rankings.