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

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章:

  • 2021-09-19
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2021-11-27
  • 2021-09-14
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2022-12-23
相关资源
相似解决方案