Nginx Force (Redirect) WWW.Domain.COM To Domain.COM

I know how to force and redirect to under Lighttpd web server. How do I force nginx web server to redirect to

You can easily redirect www to nowww domain for SEO and other purposes using the following syntax. Edit nginx.conf file, enter:
# vi /usr/local/nginx/conf/nginx.conf
To force to, enter:

### redirect www to nowww with client code 301 ###
      if ($host = '' ) {
         rewrite  ^/(.*)$$1  permanent;

Save and close the file. Test and reload nginx webserver, enter:
# /usr/local/nginx/sbin/nginx -s reload
Fire a webbrowser and type the url:
It should be redirected to

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.