我有一個AngularJs應用程序(v.1.5.7),它有像www.green.com/,www.green.com/landing,www.green這樣的明確路線。 com/home等,...我試圖使用Staticfile_buildpack在PCF中部署angularjs應用程序。我有一個內容爲「root:application」的自定義Staticfile。我在「應用程序」目錄中有我的index.html,app.js和其他angularjs控制器。適用於部署在Pivotal Cloud Foundry上的angularjs應用程序的Nginx.conf
我angularJs配置具有以下路由配置,
$routeProvider
.when("/landing", {
templateUrl: "landing/landing.html",
controller: 'LandingController'
})
在默認nginx的配置,我的基本URL(www.green.com/)&其他內部路由(如/登陸通過NG-路線& $ 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;
}
}
}
當我試圖加載我的網站,我得到一個500內部服務器錯誤&在PCF日誌下面的錯誤線。
[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文件在這種情況下。 在此先感謝!
你應該改寫你的URL在配置,對不對? –
我對Angular不熟悉,但它聽起來像要啓用推送狀態路由。 https://docs.pivotal.io/pivotalcf/1-10/buildpacks/staticfile/index.html#pushstate –
謝謝丹尼爾。我一定會嘗試推送狀態路由。 –