Nginx Redirect Generator
Create fast, error-free Nginx configuration blocks for HTTP to HTTPS, www to non-www, and URL redirects.
Nginx Redirect Generator
Write optimized server block configurations for Nginx. Handle 301 redirects, force HTTPS, and manage www vs non-www domain canonicalization flawlessly.
Nginx Configuration
Deployment Notice
Add these blocks to your nginx.conf or the specific site configuration file in /etc/nginx/sites-available/. Always test with sudo nginx -t before reloading the service.
Why use Nginx return 301 instead of rewrite?
In Nginx, it is generally recommended to use return 301 instead of rewrite for simple redirects.return stops processing and sends a response immediately to the client, making it slightly faster and less CPU intensive than regex-based rewrite rules.
Where to put these configs:
Location blocks (Single Page Redirects)
These should go inside your existing server { ... } block for your domain.
Server blocks (Domain/HTTPS/WWW Redirects)
These are standalone server { ... } blocks. They should sit alongside your main server block. For example, if you are forcing non-www, you will have one server block listening for www.example.com that redirects to example.com, and a second main server block that actually serves example.com.
Remember to reload Nginx!
After updating your configuration, always test it with nginx -t before reloading the server with systemctl reload nginx or service nginx reload.
Related Guides
Deepen your understanding with our expert articles.
