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

xiaoxiao2021-02-28  66

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 下 加粗的地方 要配置正确

405 not allowed 原因:nginx 不允许post访问静态资源 解决办法:静态server下的location加入error_page 405 =200 $uri; 参考博文
转载请注明原文地址: https://www.6miu.com/read-49631.html

最新回复(0)