运维 | 了解 nginx 配置中 root 与 alias 的区别 | nginx

本文详细解释了Nginx配置中的root与alias功能,root设置请求的根目录,而alias用于替换指定位置,两者在处理静态文件请求时的区别在于响应路径的构建。root包括配置路径和完整访问路径,而alias仅包含配置路径和静态文件名。
摘要由CSDN通过智能技术生成

运维 | 了解 nginx 配置中 root 与 alias 的区别 | nginx

  • 官方 root
Sets the root directory for requests, For example, with the following configuration

location /i/ {
    root /data/w3;
}

The /data/w3/i/top.gif file will be sent in response to the /i/top.gif request

  • 官方 alias
Defines a replacement for the specified location, For example, with the following configuration

location /i/ {
    alias /data/w3/images/;
}

on request of /i/top.gif, the file /data/w3/images/top.gif will be sent.

当访问 /i/top.gif 时,root 是去 /data/w3/i/top.gif 请求文件,alias 是去 /data/w3/images/top.gif请求,也就是说
root 响应路径:配置路径+完整访问路径(网站的location配置路径+静态文件)
alias 响应路径:配置路径+静态文件(去除location中配置的路径)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Appleex

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值