简体   繁体   English

Nginx 和 Heroku。 提供静态文件

[英]Nginx and Heroku. Serving Static Files

Goal:目标:

Going to https://secret-sands-1568.herokuapp.com/myFile.html will display the content of client/myFile.html sent by Nginx.转到https://secret-sands-1568.herokuapp.com/myFile.html会显示 Nginx 发送的client/myFile.html的内容。


From what I understand, Heroku dynos are normally used for Nodejs/Ruby/other apps but they can be converted to anything by modifying the buildrack.据我了解,Heroku dynos 通常用于 Nodejs/Ruby/其他应用程序,但可以通过修改 buildrack 将它们转换为任何内容。

In config/nginx.conf.erb , I changed location / byconfig/nginx.conf.erb ,我改变了location /

    location / {
        root   client;
        index  index.html index.htm;
    }
  • I created a file Procfile with content: web: bin/start-nginx .我创建了一个文件Procfile ,内容为: web: bin/start-nginx
  • I entered heroku config:set BUILDPACK_URL=https://github.com/ryandotsmith/nginx-buildpack.git .我输入了heroku config:set BUILDPACK_URL=https://github.com/ryandotsmith/nginx-buildpack.git

  • I entered git init heroku create git push heroku master heroku ps:scale web=1 .我输入git init heroku create git push heroku master heroku ps:scale web=1


Yet, when I go https://secret-sands-1568.herokuapp.com/myFile.html , there's nothing.然而,当我去https://secret-sands-1568.herokuapp.com/myFile.html 时,什么都没有。 Heroku logs says: 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=

What am I doing wrong?我究竟做错了什么? My goal is to have a stand-alone Nginx server that deserve static file.我的目标是拥有一个值得静态文件的独立 Nginx 服务器。

Edit : For serving static files specifically, you don't need to go through all the effort of this.编辑:对于专门提供静态文件,您无需为此付出所有努力。 There's a buildpack heroku-community/static which is hugely more simple than the nginx ones, and the instructions cater to static sites.有一个 buildpack heroku-community/static ,它比 nginx 的要简单得多,而且说明迎合了静态站点。 And I just got my Angular site working using it.我刚刚让我的 Angular 网站使用它。


I know this probably won't help the original asker, but it will probably help others who find this.我知道这可能不会帮助最初的提问者,但它可能会帮助找到这个的其他人。

Note : This is only a partial answer.注意:这只是部分答案。 I'm still looking for more debugs.我仍在寻找更多的调试。 But I managed to get mine to go from a Timeout to serving all 404 pages by doing the following.但是我通过执行以下操作设法让我的从超时到为所有 404 页提供服务。

Also note, I'm not using one from github.另请注意,我没有使用 github 中的一个。 I'm using https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx , added via heroku buildpacks:add heroku-community/nginx我正在使用https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx ,通过heroku buildpacks:add heroku-community/nginx

Procfile:简介:

web: bin/start-nginx-solo

This should serve static files instead of trying to route to another listener.这应该提供静态文件,而不是尝试路由到另一个侦听器。

So far, I keep getting nginx errors as follows: open() "/dist/index.html" failed (2: No such file or directory) (These are from app[web.1] ).到目前为止,我一直收到如下 nginx 错误: open() "/dist/index.html" failed (2: No such file or directory) (这些来自app[web.1] )。 The build was successful, but it just can't locate any of the files.构建成功,但它无法找到任何文件。 Still working on that, but at least it doesn't crash due to boot timeouts anymore.仍在努力解决这个问题,但至少它不再因启动超时而崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM