nginx配置root和alias的区别

请求资源的URL:

http://127.0.0.1/storeadmin/css/jquery.Jcrop.css


实际在机器上的地址:

/users/apple/git_local/YAE/src/storeadmin/static/css/jquery.Jcrop.css


一开始nginx配置成:

location /storeadmin {
    root    /users/apple/git_local/YAE/src/storeadmin/static;
}

结果404错误,错误日志信息:

open() "/users/apple/git_local/YAE/src/storeadmin/static/storeadmin/css/jquery.Jcrop.css" failed (2: No such file or directory)

需要改为alias:

location /storeadmin {
    alias    /users/apple/git_local/YAE/src/storeadmin/static;
}

区别在于,在location后面配置的路径,在root里不会被丢弃,而在alias会丢弃掉


你可能感兴趣的:(nginx)