sszxf 发表于 2018-11-14 06:32:37

Nginx之alias path 与root配置段的区别

  alias path 与root配置段的区别
  alias 适用于:location
  定义路径别名,文档映射的一种机制。
  在httpd中的
  alias /bbs/ /lufei/root/ 示例
  访问:http://www.lufei.com/bbs/index.html
  实际访问:http://www.lufei.com/lufei/root/index.html
  这个是以/bbs/为根。
  在nginx中的示例:
  location /bbs/ {
  alias /lufei/root/;
  }
  访问:http://www.lufei.com/bbs/index.html
  实际访问:http://www.lufei.com/lufei/root/index.html
  这个是以/bbs/为根。
  实际是将/bbs/ 换为/web/forum/,其中/web/forum/为系统中真实存在的目录,/bbs/为虚拟的目录
  另一种配置root的方法:
  location /bbs/ {
  root /lufei/root/;
  }
  访问:http://www.lufei.com/bbs/index.html
  实际访问:http://www.lufei.com/lufei/root/bbs/index.html
  这个是以root为根。
  注意:bbs/index.html 为uri。
  alias指令:给定的路径对应于location中的/uri/后面的右侧的/;
  root指令:给定的路径对应于location中的/uri/左侧的/;
  示例演示:
  root路径方法:
  01、mkdir -p /lufei/root/bbs/    创建网页目录
  02、vim index.html创建一个html文件
  
  
  
  
  
  基于域名的虚拟主机-lufei-bbs-root
  www.lufei-root.com
  
  
  03、在/etc/nginx/conf.d/目录下创建一个conf配置文件
  vim root.conf
  server {
  listen 80;
  server_name www.lufei.com;
  location /bbs/ {
  root    /lufei/root/;
  #root yuming;
  # 默认跳转到index.html页面
  index index.html;
  }
  }

  04、nginx -s>  05、访问:
  # curl www.lufei.com/bbs/
  
  
  
  
  
  基于域名的虚拟主机-lufei-bbs-root
  www.lufei-root.com
  
  
  alias路径方法:
  01、mkdir -p /nginx/bbs/    创建网页目录
  02、vim index.html创建一个html文件
  
  
  
  
  
  基于域名的虚拟主机-lufei-bbs-alias
  www.lufei-alias.com
  
  
  03、在/etc/nginx/conf.d/目录下创建一个conf配置文件
  vim alias.conf
  server {
  listen 80;
  server_name www.lufei.com;
  location /bbs/ {
  alias    /nginx/bbs/;
  # 默认跳转到index.html页面
  index index.html;
  }
  }

  04、nginx -s>  05、访问:
  # curl www.lufei.com/bbs/
  
  
  
  
  
  基于域名的虚拟主机-lufei-bbs-alias
  www.lufei-alias.com
  
  

页: [1]
查看完整版本: Nginx之alias path 与root配置段的区别