【发布时间】:2018-01-11 22:37:08
【问题描述】:
我有一个 AngularJs 应用程序 (v.1.5.7),它有明确的路线,如 www.green.com/ 、 www.green.com/landing 、 www.green.com/home 等……我'我尝试使用 Staticfile_buildpack 在 PCF 中部署 angularjs 应用程序。我有一个自定义静态文件,其内容为“根:应用程序”。我在“应用程序”目录中有我的 index.html、app.js 和其他 angularjs 控制器。
我的 angularJs 配置有以下路由配置,
$routeProvider
.when("/landing", {
templateUrl: "landing/landing.html",
controller: 'LandingController'
})
使用默认的 nginx 配置,我的基本 url (www.green.com/) 和其他内部路由(例如 /landing 通过 ng-route 和 $location.path)得到了正确的服务。但是当我刷新登录页面(www.green.com/landing)时,它给了我一个 404 Not Found 错误。我了解到 nginx 正在尝试在这里找到名为“landing”的目录。
在页面刷新的情况下,我尝试通过自定义 nginx.conf 将请求重定向回我的基本 url,以便加载我的 index.html。 我现在的 nginx.conf 如下所示,
http{
server {
listen <%=ENV["PORT"] %>;
index index.html;
location /landing {
rewrite ^ http://$host? permanent;
}
location /{
try_files $uri $uri/ $uri.html /index.html;
}
}
}
当我尝试加载我的网站时,我在 PCF 日志中收到 500 内部服务器错误和以下错误行。
[error] 54#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html",
但是,当我尝试加载 www.green.com/landing 时,它会成功重定向到我的基本 url,然后给我一个 500 内部服务器错误。
我尝试了以下 nginx.conf
http{
server {
listen <%=ENV["PORT"] %>;
index /application/index.html;
rewrite "^/landing" /application/index.html last;
}
}
但我收到 404 Not Found 错误,PCF 日志中出现以下错误,
[error] 49#0: *3 open() "/home/vcap/app/nginx/html/application/index.html" failed (2: No such file or directory),
在这种情况下,请帮助我创建一个有效的自定义 nginx.conf 文件。 提前致谢!
【问题讨论】:
-
你应该在config中重写你的url,对吧?
-
我对 Angular 不熟悉,但听起来您想启用推送状态路由。 docs.pivotal.io/pivotalcf/1-10/buildpacks/staticfile/…
-
谢谢丹尼尔。我一定会尝试推送状态路由。
标签: angularjs nginx static-files cloud-foundry