在Pivotal Cloud Foundry上部署的angularjs应用程序的Nginx.conf

时间:2017-04-10 13:15:57

标签: angularjs nginx cloudfoundry static-files pivotal-cloud-foundry

我有一个AngularJs应用程序(v.1.5.7),它有明确的路线,如www.green.com/,www.green.com/landing,www.green.com/home等,......我和# 39; m尝试使用Staticfile_buildpack在PCF中部署angularjs应用程序。我有一个自定义静态文件,内容为" root:application"。我在"应用程序"中有我的index.html,app.js和其他angularjs控制器。目录。

我的angularJs配置具有以下路由配置,

$routeProvider
.when("/landing", {
        templateUrl: "landing/landing.html",
        controller: 'LandingController'
    })

使用默认的nginx配置,我的基本网址(www.green.com/)&其他内部路线(例如,通过ng-route& $ location.path着陆)得到了适当的服务。但是当我刷新登陆页面(www.green.com/landing)时,它会给我一个404 Not Found错误。我知道nginx正试图找到名为"登陆"的目录。这里。

如果页面刷新,我尝试通过自定义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;
        }
    }   
}

当我尝试加载我的网站时,我收到500内部服务器错误&amp; PCF日志中的以下错误行。

[error] 54#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html",

但是,当我尝试加载www.green.com/landing时,它会成功重定向到我的基本网址,然后给我一个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文件。 提前谢谢!

1 个答案:

答案 0 :(得分:0)

如果您在代码中启用了chown -R user:usergroup folder/*,则需要在索引file.along中设置基本标记,

html5Mode

这是角网站的Nginx重写。