location uri 添加 / 和不添加 / 的区别?

#不添加/,默认上/code/test目录下找index.html文件,如果没有 index.html则会查找/code/test文件
location /test {
    root /code;
    index index.html;
}
	
#添加/,默认上/test目录下寻找index.html文件,如果没有index.html 则会直接返回404 
location /test/ {
    root /code;
}

#示例测试代码
[root@oldxu code]# cat /etc/nginx/conf.d/uri.oldxu.net.conf 
	server {
    listen 80;
		server_name uri.oldxu.net;
		root /code;

	#	location /test {
	#		index index.html;
	#	}

		location /test/ {
			index index.html;
		}
	}
posted @ 2021-08-11 16:33  oldxulinux  阅读(497)  评论(0编辑  收藏  举报