zoukankan      html  css  js  c++  java
  • nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别

    1、多级目录配置

    多级目录是指像/html/mypage 等等配置:

    server {
            listen       80;
            server_name  localhost;
    
            location = /page1/ {                         #这里的=号是精准配置
                root  /usr/local/nginx/html/page1/;      #最前面的加上/,是绝对路径地址,建议这样定位文件夹目录。
                index page1.html;
            }
    
            location = /alias/ {
                alias  /usr/local/nginx/html/alias/;         #alias配置的文件夹目录最末尾一定要加上/
                index  index.html;
            }
    
            location / {
                root   html;                             # html前面没有/,代表相对路径,指的是nginx安装根目录下的html文件夹
                index  index.html index.htm;             # html文件夹下首先访问index.html,如果不存在,则第二选择访问index.htm
            }
    
            error_page   500 502 503 504  /50x.html;     #定义http错误码,和http错误码跳转url
            location = /50x.html {
                root   html;
            }
         }

    2、root和alias的区别

    感谢这位老兄:  https://www.cnblogs.com/my_life/articles/7070805.html 《nginx配置 location root》

    alias 指定的目录是准确的,给location指定一个目录。
    root 指定目录的上级目录,并且该上级目录要含有locatoin指定名称的同名目录。


    以root方式设置资源路径:

    语法: root path;
    配置块: http、server、location、if

    以alias 方式设置资源路径:

    语法: alias path;
    配置块: location

    Example:

    location /img/ {
        alias /var/www/image/;
    }
    #若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
    location /img/ {
        root /var/www/image;
    }
    #若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件

    3、错误日志查看
    如果文件找不到,可以查看错误日志:logs/error.log,一般会告诉你nginx去哪个路径下找资源了,可以反查nginx.conf配置路径是否正确。
     
  • 相关阅读:
    Azure HPC Pack Cluster添加辅助节点
    Azure HPC Pack 辅助节点模板配置
    Azure HPC Pack配置管理系列(PART6)
    Windows HPC Pack 2012 R2配置
    Azure HPC Pack 节点提升成域控制器
    Azure HPC Pack VM 节点创建和配置
    Azure HPC Pack 部署必要条件准备
    Azure HPC Pack 基础拓扑概述
    Azure VM 性能计数器配置
    Maven私仓配置
  • 原文地址:https://www.cnblogs.com/zhuwenjoyce/p/10878804.html
Copyright © 2011-2022 走看看