zoukankan      html  css  js  c++  java
  • Nginx静态文件路径配置

    root目录与alias目录的区别

    Nginx路径location配置中,使用root目录与alias目录的区别


        1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alias目录下查找的;
        2)root指定的目录是location匹配访问的path目录的上一级目录,这个path目录一定要是真实存在root指定目录下的;

    举例说明


        比如静态资源文件在服务器/var/www/static/目录下

        1)配置alias目录


        location /static/ {
            alias  /var/www/static/;
        }

        注意:alias指定的目录后面必须要加上"/",即/var/www/static/不能改成/var/www/static
        
        访问http://IP:PORT/static/index.html时,实际访问的是/var/www/static/index.html
        

        2)也可改成配置root目录


        location /static/ {
            root  /var/www/;
        }

        注意:location中指定的/static/必须是在root指定的/var/www/目录中真实存在的。
          
        两者配置后的访问效果是一样的。 

    配置习惯  

      
        一般情况下,在nginx配置中的良好习惯是:
        1)在location / 中配置root目录
        2)在location /somepath/ 中配置alias虚拟目录
        

    配置默认主页


        比如访问 http://IP:PORT/,默认访问服务器/var/www/static/目录下的index.html
        

        1)配置alias目录方式

        
        location / {
            alias  /var/www/static/;
            index  index.html index.htm;
        }
        

        2)配置root目录方式

        
        location / {
            root  /var/www/static/;
            index  index.html index.htm;

        }

  • 相关阅读:
    Binary Tree Level Order Traversal II
    图和图的遍历算法
    Remove Duplicates from Sorted List
    Binary Tree Preorder Traversal
    Merge Sorted Array
    [POJ2774][codevs3160]Long Long Message
    [BZOJ2251][2010Beijing Wc]外星联络
    [BZOJ1692][Usaco2007 Dec]队列变换
    [BZOJ1717][Usaco2006 Dec]Milk Patterns 产奶的模式
    [BZOJ1131][POI2008]Sta
  • 原文地址:https://www.cnblogs.com/azhqiang/p/9772089.html
Copyright © 2011-2022 走看看