nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css


nginx 找不到 css nginx 找不到静态资源_centos_02


nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_03


nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_04


这是我的nginx.conf配置文件:

nginx 找不到 css nginx 找不到静态资源_nginx_05


这是nginx根目录:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_06


里面有个test文件夹,test文件夹里面有一个find_me.html页面和另一个文件夹xxoo:

nginx 找不到 css nginx 找不到静态资源_linux_07


find_me.html打开是这样的:

nginx 找不到 css nginx 找不到静态资源_html_08


xxoo文件夹里面也有一个find_me.html:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_09


xxoo里面的find_me.html打开是这样的:

nginx 找不到 css nginx 找不到静态资源_html_10


到此为止,我们在nginx根目录里面的静态资源都准备好了,下面在非nginx根目录中的静态资源,我们就在系统根目录新建一个data文件夹:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_11


data中有两个文件夹image和www:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_12


image中有张图片:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_13


www中有个static_web.html:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_14


打开是遮这样的:

nginx 找不到 css nginx 找不到静态资源_nginx_15


准备完毕,接下来我们对照nginx.conf配置文件来测试:

首先测试nginx默认页面:默认页面路径http://192.168.252.130/对应的就是蓝色框中的配置,/代表根目录,root html代表根目录中的html文件夹,也就是访问/时候,去nginx根目录中的html文件夹找页面:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_16


nginx 找不到 css nginx 找不到静态资源_nginx_17


nginx 找不到 css nginx 找不到静态资源_linux_18

nginx 找不到 css nginx 找不到静态资源_nginx_19


接着测试http://192.168.252.130/xxoo/find_me.html

nginx 找不到 css nginx 找不到静态资源_centos_20


路由http://192.168.252.130/xxoo/find_me.html命中蓝色框中的/xxoo/, 于是去根目录中的test文件夹寻找xxoo文件夹里面的页面,是可以找到的:

nginx 找不到 css nginx 找不到静态资源_nginx 找不到 css_21


接着测试http://192.168.252.130/www/static_web.html:

nginx 找不到 css nginx 找不到静态资源_linux_22


路由http://192.168.252.130/www/static_web.html命中/www/配置项,于是去系统根目录找/data/www/文件夹里面的页面,是可以找到的:

nginx 找不到 css nginx 找不到静态资源_centos_23


最后我们测试http://192.168.252.130/image/

nginx 找不到 css nginx 找不到静态资源_centos_24


路径http://192.168.252.130/image/命中了/image/,于是在系统根目录下找/data/image这个文件夹,因为开启了autoindex,所以显示

nginx 找不到 css nginx 找不到静态资源_html_25


如果我们直接访问:http://192.168.252.130/image/bunny.jpg,路由命中/image/,于是在系统根目录找/data/image/bunny.jpg文件,找到了,就显示出来:

nginx 找不到 css nginx 找不到静态资源_linux_26


有个技巧,就是查看ngxin错误日志:

我们先切换到nginx日志文件夹中:

nginx 找不到 css nginx 找不到静态资源_nginx_27


查看动态日志:tail -f error.log

nginx 找不到 css nginx 找不到静态资源_html_28

比如我们输入一个错误的路径:

nginx 找不到 css nginx 找不到静态资源_html_29


回到刚才的日志页面,就会显示出错位置和原因:

nginx 找不到 css nginx 找不到静态资源_centos_30