Depending on your requirements you’ll need to redirect your users from domain.com to www.domain.com with a permanent redirect in order to improve your site SEO ranking. We already know how to do it with apache and mod_rewrite, but how do you make it in nginx ? It’s not too hard.
Apache configuration:
#.htaccess RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.domain\.com RewriteRule (.*) http://www.domain.com$1 [R=301,L]
Nginx configuration:
# /etc/nginx/nginx.conf if ($http_host !~ "^www\.domain\.com$") { rewrite ^(.*) http://www.domain.com$1 permanent; }