入职新公司 自己配置nginx 

开箱即用 不管是本地还是远程的主机都没有问题

问题出现在了nginx的配置上

cd到nginx里面的conf 中 vi nginx.conf

location /images {  #路径
root /usr/local/src/test;  #指向的资源
autoindex on; #展示目录
}

  

同时在主机上面对应的路径 /usr/local/src/test 放了一个test.html 一个zui.jpg

在浏览器中打开 localhost/images/test.htm 或者 服务器ip/images/zui.jpg 

问题来了 404 

省略过程,直接说结论 

root 指定的目录 会把匹配的路径加在 目录后面 即 我们访问的资源路径 其实是 /usr/local/src/test/images/

可并没有 images这个文件夹 所以报404

解决:

alias 指定目录  再打开 localhost/images/test.html 就不会报错了 (说明:第二行 可以设置 index 或者 autoindex )

location /images {  #路径
alias /usr/local/src/test;  #指向的资源
index test.html; #默认资源
}

相关文章:

  • 2022-12-23
  • 2021-07-09
  • 2022-01-22
  • 2022-12-23
  • 2021-07-03
  • 2021-09-12
  • 2021-11-24
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-06
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
相关资源
相似解决方案