[英]Nginx and Heroku. Serving Static Files
目標:
轉到https://secret-sands-1568.herokuapp.com/myFile.html會顯示 Nginx 發送的client/myFile.html
的內容。
據我了解,Heroku dynos 通常用於 Nodejs/Ruby/其他應用程序,但可以通過修改 buildrack 將它們轉換為任何內容。
tmp
的文件夾,其中包含一個app-initialized
文件。client
的文件夾,其中包含一個文件myFile.html
。 在config/nginx.conf.erb
,我改變了location /
location / {
root client;
index index.html index.htm;
}
Procfile
,內容為: web: bin/start-nginx
。 我輸入了heroku config:set BUILDPACK_URL=https://github.com/ryandotsmith/nginx-buildpack.git
。
我輸入git init
heroku create
git push heroku master
heroku ps:scale web=1
。
然而,當我去https://secret-sands-1568.herokuapp.com/myFile.html 時,什么都沒有。 Heroku 日志說:
2015-05-19T07:13:32.990254+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:33.995458+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:34.998228+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:36.000823+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:37.005955+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:38.008548+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:39.011184+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:40.013788+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:41.016516+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:42.019372+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:43.023551+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:44.029985+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:45.035183+00:00 app[web.1]: buildpack=nginx at=app-initialization
2015-05-19T07:13:45.910618+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-05-19T07:13:45.910618+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-05-19T07:13:46.732519+00:00 heroku[web.1]: State changed from starting to crashed
2015-05-19T07:13:46.718745+00:00 heroku[web.1]: Process exited with status 137
2015-05-19T07:17:12.890713+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-caverns-1927.herokuapp.com request_id=6d15e849-ce45-41bc-9bad-60d9eb0454ef fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
2015-05-19T07:17:13.039723+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-caverns-1927.herokuapp.com request_id=7aeecc36-05b5-4799-bf0a-6ba97b2a6190 fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
2015-05-19T07:17:18.350029+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/myFile" host=obscure-caverns-1927.herokuapp.com request_id=cb77356f-ddf3-4795-b56d-fa9cde5d134a fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
2015-05-19T07:17:18.471762+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-caverns-1927.herokuapp.com request_id=64a89596-b287-4b89-a3ce-ed750e4fb1c1 fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
2015-05-19T07:17:22.250495+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=obscure-caverns-1927.herokuapp.com request_id=4ccda4e8-1532-49dc-8658-e67312ef333d fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
2015-05-19T07:17:22.125124+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/myFile.html" host=obscure-caverns-1927.herokuapp.com request_id=33cdee81-2dda-44cb-acf7-2dc5b4156ef2 fwd="24.200.222.98" dyno= connect= service= status=503 bytes=
我究竟做錯了什么? 我的目標是擁有一個值得靜態文件的獨立 Nginx 服務器。
編輯:對於專門提供靜態文件,您無需為此付出所有努力。 有一個 buildpack heroku-community/static ,它比 nginx 的要簡單得多,而且說明迎合了靜態站點。 我剛剛讓我的 Angular 網站使用它。
我知道這可能不會幫助最初的提問者,但它可能會幫助找到這個的其他人。
注意:這只是部分答案。 我仍在尋找更多的調試。 但是我通過執行以下操作設法讓我的從超時到為所有 404 頁提供服務。
另請注意,我沒有使用 github 中的一個。 我正在使用https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx ,通過heroku buildpacks:add heroku-community/nginx
簡介:
web: bin/start-nginx-solo
這應該提供靜態文件,而不是嘗試路由到另一個偵聽器。
到目前為止,我一直收到如下 nginx 錯誤: open() "/dist/index.html" failed (2: No such file or directory)
(這些來自app[web.1]
)。 構建成功,但它無法找到任何文件。 仍在努力解決這個問題,但至少它不再因啟動超時而崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.