#故障分析 1,nginx 在一个域名的情况下,会根据 location去匹配不同的目录。或代理到不同的应用上。 2,部分测试匹配规则,具体解释详见另一篇nginx配置详解的文章 ##20190321_test ##location = /fuhai/ { ##1,测试无效 #location ~* /fuhai/ { ##2,可以访问test.html 但无法访问.css .js 的文件 #location ~ /fuhai/ { ##3,同上 #location ^~ /fuhai/ { ##4,同上 root /data/nginx/files/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } #location ~* \.(css|js)$ { ##5,貌似解决不了匹配问题 # root /data/nginx/files/fuhai/static/; #} location ~* /static { ##6,解决.css .js文件所在目录 root /data/nginx/files/fuhai/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
解决办法:
第一种办法,是开发在代码中将.css .js所在的文件夹目录改为当前目录,见截图:
修改后:
上面这种方式nginx,只需配置第2;3;4方式均可解决。
第二种方法,通过nginx来处理:
#20190321_test ##location = /fuhai/ { #location ~ /fuhai/ { #location ^~ /fuhai/ { location ~* /fuhai/ { root /data/nginx/files/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location ~* /static { root /data/nginx/files/fuhai/; } ## location ~* /static { 为了处理.css .js 文件用
访问测试:
测试成功。