6, nginx 的 root 和 alias 及 return 指令

Nginx配置的root和alias的区别:
root和alias都可以定义在location模块中,都是用来指定请求资源的真实路径,比如:
location /i/ {
  root /data/w3;
}
请求 http://www.etiantian.org/i/top.gif 这个地址时,那么在服务器里面对应的真正的资源是 /data/w3/i/top.gif文件

注意:真实的路径是root指定的值加上location指定的值 。


而 alias 正如其名,alias指定的路径是location的别名,不管location的值怎么写,资源的 真实路径都是 alias 指定的路径 ,比如:
location /i/ {
  alias /data/w3/;
}
同样请求 http://www.etiantian.org/i/top.gif 时,在服务器查找的资源路径是: /data/w3/top.gif

其他区别:
    1、 alias 只能作用在location中,而root可以存在server、http和location中。
    2、 alias 后面必须要用 “/” 结束,否则会找不到文件,而 root 则对 ”/” 可有可无。
	
	



error_page 502 503 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}
这样实际上产生了一个内部跳转(internal redirect),当访问出现502、503的时候就能返回50x.html中的内容。

error_page 502 503 =200 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}   
这样用户访问产生502 、503的时候给用户的返回状态是200,内容是50x.html。



 

  

猜你喜欢

转载自www.cnblogs.com/k8s-pod/p/13378989.html