Date Posted:11-03-2017

In this post, we deals with how to redirect all non www request to www request. If nginx is not installed, follow the posts.

  1. Ubuntu 16.04
  2. Centos 7

Implementation:

If you followed the above posts, the default location of nginx configuration isĀ /etc/nginx/sites-enabled/default.

Open nginx configuration and add the following lines.

vi /etc/nginx/sites-enabled/default

server {
    listen 80;
    server_name domain.tld;

    return 301 http://www.domain.tld$request_uri;
}

Check the syntax error

nginx -t

If there is no error, restart the nginx service to make the changes come to effect.

/etc/init.d/nginx restart

 

 

Leave a Reply