Date Posted:21-03-2017

Normally, we requires multiple domain names or wildcard domain name (*) or  www  points to same directory. In apache, we use ServerAlias to achieve the same. In this post, we will explain on how to add Serveralias on Nginx webserver.

If nginx is not installed, please follow the below post to install nginx webserver.

 

 

Implementation:

We assumes that we would like to add www as a Server Alias on nginx. So, whatever request whether its www or nonwww, the request will go to same document root.

Open the domain configuration. If you followed above articles then there will be only one domain configuration ie., default

vi /etc/nginx/sites-available/default

Changes the line from,

server_name _;

to,

server_name domain.tld www.domain.tld;

Give a space and you can add many number of domains. If the nginx domain configuration is different, we need to update corresponding domain configuration.

Check the nginx configuration syntax errors

nginx -t

Restart nginx configuration to make changes comes into effect.

service nginx reload

 

Leave a Reply