0
点赞
收藏
分享

微信扫一扫

关于nginx网站路径配置中的root与alias

q松_松q 2024-11-04 阅读 18
nginx运维
  • root:指定web的家目录,在定义location的时候,文件的绝对路径等于 root+location
  • alias:定义路径别名,会把访问的路径重新定义到其指定的路径,是文档映射的另一种机制;另外仅能用于location上下文

root的用法例子

需要在/web/uhn目录下创建一个news目录,放置网站的文件。

[root@localhost conf.d]# cat uhn.conf 
server {
   listen 80;
   server_name www.uhn.cn;
   
   location / {
   root /data/nginx/html/uhn;
   }

   location /news {
   root /web/uhn;
   }
}

alias的用法例子

[root@localhost conf.d]# vi uhn.conf 

server {
   listen 80;
   server_name www.uhn.cn;

   location / {
   root /data/nginx/html/uhn;
   }

   location /news {
   root /web/uhn;
   }

   location /sport {
   alias /web/uhn/sport;
   }

}

准备数据


[root@localhost ~]# cd /web/uhn/
[root@localhost uhn]# tree
├── news

│   └── index.html

└── sport

    └── index.html

  • root 给定的路径对应于location中的/uri 左侧的/
  • alias 给定的路径对应于location中的/uri 的完整路径


举报

相关推荐

0 条评论