jpg 404

回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

jpg 404

文章 yehlu »

https://www.cnblogs.com/cxscode/p/6978464.html

nginx访问css js 图片等静态资源,报404或无法定向访问到
配置完nginx,把php的项目放上去后,发现css,js和图片全部访问不到,一直重定向到根目录执行index.php,郁闷的在网上查了半天,原来不同后缀名的文件访问时都要在nginx.conf中声明规则,如下,

1
2
3
4
5
6
7
location ~* .(jpg|gif|png|js|css)$ {
root E:\Project\PHP\mobao;
if (-f $request_filename) {
expires max;
break;
}
}
  在location ~ \.php$前面加上上面这段规则,重启nginx,刷新网页,访问成功!!!

复制代码
location ~* .(jpg|gif|png|js|css)$ {
root E:\Project\PHP\mobao;
if (-f $request_filename) {
expires max;
break;
}
  }

location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9009;
fastcgi_index index.php;
...
复制代码
如果是只有根目录首页INDEX.PHP能访问,其他页面404,请看我的另一篇博文 http://www.cnblogs.com/cxscode/p/6978428.html
回覆文章

回到「nginx」