[Nginx] nginx.conf中root和alias的区别

阿里云服务器,创建自己的专属站点

每次建新项目都会在配nginx时浪费时间,配好之后没留文档记录,导致下次继续浪费时间,今次就书面总结了却顽疾。

1. root
如果用root,若访问location路径,则定位到:root 路径 + location路径,下例中就是:
/usr/local/nginx/test/index.html

	location /test {
		root /usr/local/nginx;
		index index.html index.htm;
	}

2. alias (别名)
如果用alias,若访问location路径,则定位到alias路径

	location /test {
		alias /usr/local/nginx;
		index index.html index.htm;
	}
	//最终路径:usr/local/nginx/index.html
	location /test {
		alias /usr/local/nginx/test;
		index index.html index.htm;
	}
	//最终路径:usr/local/nginx/test/index.html
	location /test2 {
		alias /usr/local/nginx/test1;
		index index.html index.htm;
	}
	//访问/test2 , 最终路径:usr/local/nginx/test1/index.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值