L63-65

alias指令 

syntax: alias path;# 静态文件路径  alias不会将请求路径后的路径添加到 path中

context : location;

root指令

syntax : root path; #静态文件路径 root会将请求路径后添加的 path中

context : http,server,location,if in location

      location /root {
root html;
}
location /alias{
alias html;
} location ~/root/(\w+\.txt){
root html/first/$;
}
location ~/alias/(\w+\.txt){
alias html/first/$;
}

访问 http://xxxx/root 返回404 通过error日志 可以看到 会在html后加上root目录

访问 http://xxxx/alias 返回nginx主页面 返回正确

访问 http://xxxx/root/1.txt 返回404

访问 http://xxxx/alias/1.txt 则返回1.txt内容

 static模块三个变量

request_filename : 访问文件的完整路径包括扩展名

document_root : 由URI和root/alias规则生成的文件夹路径 

realpath_root : 将document_root软连接替换成真实路径

location /realpath{
alias html/realpath;
return '$request_filename:$document_root:$realpath_root\n';
}

访问 http://xxxx/realpath/1.txt 则返回 /usr/local/nginx/html/realpath/1.txt:/usr/local/nginx/html/realpath:/usr/local/nginx/html/realpath 输出的路径

当用户访问资源时没有在末尾加反斜杠的时候 NGINX会返回一个301的重定向

 指令 absolute_redirect  

syntax: on | off;

default : on;

context : http,server,location

 server {
listen ;
server_name localhost; absolute_redirect off; #关闭的时候
port_in_redirect on;
}

演示:当关闭absolute_redirect的时候 curl http://116.196.123.9/alias -i

当访问后  看到头部是不带域名的

Server: nginx/1.14.2
Date: Fri, 15 Feb 2019 08:26:21 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: /alias/  #我们看到没有完整域名

当打开的时候 就有 Location: http://192.xxx.xxx.1/alias/

指令 port_in_redirect 

syntax : on | off;

defaut : on;

context : http,server,location;

指令 server_name_in_redirect 主要控制 是否返回的 host域名 还是server_name主域名

syntax : on | off;

default : off;

context : http,server,location;

最新文章

  1. smarty 模板几个例子
  2. Windows进程崩溃问题定位方法
  3. 解决java使用https协议请求出现证书不信任问题(PKIX path building failed)
  4. iOS 导航栏实现总结
  5. JavaScript读二进制文件并用ajax传输二进制流
  6. JS手动触发事件,转载
  7. sudo gem install cocoapods 没反应问题
  8. POJ2047 Concert Hall Scheduling(最小费用最大流)
  9. FFTW简介及使用
  10. bzoj4709 [jsoi2011]柠檬
  11. js 判断页面加载状态
  12. 在ASP.NET将程序中将上传的附件存储到另一台文件服务器上的实现
  13. pydev package包中__init__.py作用
  14. 【SVN】is out of date
  15. 数据结构之合并链表STL
  16. PHP Zip File 函数
  17. JMeter二次开发(1)-eclipse环境配置及源码编译
  18. Elasticsearch大规模时序索引如何治理和规划
  19. Gvim:unable to load python
  20. 微信小程序获取formId时提示"the formId is a mock one"

热门文章

  1. linux调度器源码分析 - 运行(四)
  2. linux驱动编写之进程独占驱动
  3. NOIP2002-2017普及组题解
  4. 51Nod 1677 treecnt
  5. [Spark][Python]Mapping Single Rows to Multiple Pairs
  6. scikit-learn的线性回归模型
  7. mysql大数据量下的分页
  8. 【JVM.6】虚拟机类加载机制
  9. Spring学习日志之纯Java配置的MVC框架搭建
  10. Asp.Net_ 服务端向客户端写JavaScript脚本