一、多级目录配置html
多级目录是指像/html/mypage 等等配置:nginx
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;
}
}
二、root和alias的区别ui
感谢这位老兄: https://www.cnblogs.com/my_life/articles/7070805.html 《nginx配置 location root》url
alias 指定的目录是准确的,给location指定一个目录。
root 指定目录的上级目录,而且该上级目录要含有locatoin指定名称的同名目录。spa
以root方式设置资源路径:3d
语法: root path;
配置块: http、server、location、if
以alias 方式设置资源路径:日志
语法: alias path;
配置块: location
Example:code
location /img/ { alias /var/www/image/; }
#若按照上述配置的话,则访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
root /var/www/image;
}
#若按照这种配置的话,则访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件
三、错误日志查看
若是文件找不到,能够查看错误日志:logs/error.log,通常会告诉你nginx去哪一个路径下找资源了,能够反查nginx.conf配置路径是否正确。
