Naked Domain Redirect on NGINX

Asif Ahmed

This will be a quick snippet post about a problem I encountered today. What’s the best way to redirect your naked domain (like to “” in your browser, if you are using nginx as your server?

In nginx you could use an if statement to check and then redirect, but this is bad practice. Recommended practice is just this to add your nginx config file for your specific website:

server {


return 301 $scheme://$request_uri;


After you add this snippet, then restart your nginx server and all requests to your naked domain should be rerouted through www + your domain.