Understanding Root and Alias directive in NGINX

Posted By : Ravi Verma | 25-Apr-2015
Understanding Root & Alias in NGINX

With "alias" you can set alias to another file name, like

		location /users.txt { 
			alias /home/www/static-files/filename.txt; 
		}
    

whereas

		location /users.txt { 
			root /home/www/static-files/; 
		}
    

forces you to name your file as robots.txt


in others words.

when you use root, location added to to the root

		ex : 
		location /users.txt { 
			root /home/www/static-files; 
		}
    

result : /home/www/static-files/users.txt

when you use alias, location added to to the alias

		ex:
		location /users.txt { 
			alias /home/www/static-files/users.txt; 
		}
    

result : /home/www/static-files/users.txt

Hope you find it helpful.

About Author

Author Image
Ravi Verma

Ravi is a seasoned technologist with excellent experience in AngularJS , NodeJS and MEAN stack. He has good experience in developing complex UIs for web and mobile applications.

Request for Proposal

Name is required

Comment is required

Sending message..