nginx 下 angular应用 出现错误状态码问题总结

  1. 404
    场景1: angular restful 风格路由 nginx服务器 无法识别
    解决办法:
    三步:
    a 入口html文件 头部 添加base标签
    b 配置angular路由(ui-router)需指定html5Mode
    $locationProvider.html5Mode(true).hashPrefix(“!”);
    c nginx.conf 文件下添加如下配置
 location {...try_files $uri $uri/ /index.html =404...}

场景2: angular http 访问后台php文件 出现 404
原因: nginx配置解析php出现问题 一般是如:

   location ~ \.php$ {
           root  **D:/article-system/backend**;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  **D:/article-system/backend**$fastcgi_script_name;
           include        fastcgi_params;
       }

root目录配置错误,导致服务器无法找到请求的php文件 ,注意在前端代码http请求的api路径要以 php 所在目录 root为 初始路径。
解决方法:root 和 fastcgi_param 下 加粗的地方 要配置正确

  1. 405 not allowed
    原因:nginx 不允许post访问静态资源
    解决办法:静态server下的location加入error_page 405 =200 $uri;
    参考博文

你可能感兴趣的:(AngularJs,前端性能)