Nginx和Heroku.提供静态文件 [英] Nginx and Heroku. Serving Static Files

查看:57
本文介绍了Nginx和Heroku.提供静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:

转到 https://secret-sands-1568.herokuapp.com/myFile.html 将显示Nginx发送的 client/myFile.html 的内容.

Going to https://secret-sands-1568.herokuapp.com/myFile.html will display the content of client/myFile.html sent by Nginx.

据我了解,Heroku dynos通常用于Nodejs/Ruby/其他应用程序,但是可以通过修改buildrack将其转换为任何东西.

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.

  • I copied the content of https://github.com/theoephraim/nginx-buildpack.
  • I added a folder named tmp with a file app-initialized.
  • I added a folder named client with a file myFile.html.

config/nginx.conf.erb 中,我通过

    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日志说:

    Yet, when I go https://secret-sands-1568.herokuapp.com/myFile.html, there's nothing. Heroku logs says:

    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服务器.

    What am I doing wrong? My goal is to have a stand-alone Nginx server that deserve static file.

    推荐答案

    编辑:为了专门提供静态文件,您无需花费所有精力.有一个buildpack heroku-community/static 比起简单得多Nginx的,说明适应静态站点.我刚刚在Angular网站上使用它.

    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. And I just got my Angular site working using it.

    我知道这可能不会帮助原始的申请者,但可能会帮助其他人.

    I know this probably won't help the original asker, but it will probably help others who find this.

    注意:这只是部分答案.我仍在寻找更多调试信息.但是通过执行以下操作,我设法使我的服务器从超时"变为可以处理所有404页.

    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.

    还请注意,我没有使用github上的一个.我正在使用 https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx ,通过 heroku buildpacks添加:add heroku-community/nginx

    Also note, I'm not using one from github. I'm using https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-nginx, added via 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.

    到目前为止,我一直收到如下的nginx错误: open()"/dist/index.html"失败(2:没有这样的文件或目录)(这些来自 app [web.1] ).构建成功,但是无法找到任何文件.仍然可以解决此问题,但至少不会因启动超时而崩溃.

    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]). 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.

    这篇关于Nginx和Heroku.提供静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆