When managing a website or application on your VPS, redirects are essential for controlling how traffic flows between URLs. Whether you’re moving to HTTPS, redirecting an old domain, or cleaning up broken links, Nginx makes it easy and efficient to handle redirections at the web server level.
In this guide, we’ll cover how to configure different types of redirects in Nginx, including:
Permanent redirects (301)
Temporary redirects (302)
HTTP to HTTPS
Non-www to www (and vice versa)
Path-specific rewrites
A VPS with Nginx installed
Root or sudo access
Your site’s config file (typically in /etc/nginx/sites-available/ or /etc/nginx/conf.d/)
Use this when a URL or domain has changed permanently.
🔐 Tip: Always redirect to HTTPS when possible.
Use this for temporary redirection (e.g., during maintenance).