【问题标题】:Heroku + docker + nginx every request returns 500Heroku + docker + nginx 每个请求返回 500
【发布时间】:2017-05-21 10:35:38
【问题描述】:

我将我的 docker 容器部署到 Heroku 主机。容器包含 nginx 和静态文件,由 webpack 在包含构建阶段创建。 根目录是 /data/www,包含 index.html、style.css、style.css.map、bundle.js、vendor.bundle.js 和包含资产(图像/等)的目录

我的 nginx 配置文件:

worker_processes auto;

events {
    use epoll;
    multi_accept on;
}

http {
    access_log /dev/stdout;
    error_log /dev/stdout info;
    server {
        include listen.conf;

        types{
            text/javascript   js;
            text/css          css;
            image/jpeg        jpg;
            image/png         png;
        }
        default_type text/html;

        root /data/www;
        index /index.html;
        location / {
            try_files $uri $uri/ /index.html;
        }
    }
}

它在本地工作,但是当我将图像推送到 Heroku 时:

docker build -t registry.heroku.com/tp-frontend-kv/web .
docker push registry.heroku.com/tp-frontend-kv/web

每个请求返回500,nginx登录Heroku:

2017-05-21T10:31:09.254234+00:00 heroku[router]: at=info method=GET path="/" host=tp-frontend-kv.herokuapp.com request_id=63388b37-4b9b-432b-88c2-8ae393e2708d fwd="178.22.54.74" dyno=web.1 connect=1ms service=1ms status=500 bytes=355 protocol=https

2017-05-21T10:31:09.256223+00:00 app[web.1]: 2017/05/21 10:31:09 [error] 14#14: *4 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 10.84.188.241, server: , request: "GET / HTTP/1.1", host: "tp-frontend-kv.herokuapp.com", referrer: "https://dashboard.heroku.com/"

2017-05-21T10:31:09.256368+00:00 app[web.1]: 10.84.188.241 - - [21/May/2017:10:31:09 +0000] "GET / HTTP/1.1" 500 193 "https://dashboard.heroku.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"

2017-05-21T10:31:14.935539+00:00 app[web.1]: 2017/05/21 10:31:14 [error] 13#13: *5 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 10.84.188.241, server: , request: "GET /index.html HTTP/1.1", host: "tp-frontend-kv.herokuapp.com"

2017-05-21T10:31:14.935653+00:00 app[web.1]: 10.84.188.241 - - [21/May/2017:10:31:14 +0000] "GET /index.html HTTP/1.1" 500 193 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"

2017-05-21T10:31:14.934805+00:00 heroku[router]: at=info method=GET path="/index.html" host=tp-frontend-kv.herokuapp.com request_id=c7a3943b-3714-4745-8758-37002e735d6e fwd="178.22.54.74" dyno=web.1 connect=0ms service=2ms status=500 bytes=355 protocol=https

可能是什么问题?

PS dockerfile 和其他:github

【问题讨论】:

    标签: nginx heroku


    【解决方案1】:

    在部署之前,通过运行(需要 heroku cli)来关注您的日志:

    $ heroku logs --app <your-app> -t
    

    您可能会看到导致 500 响应的 nginx 启动错误,例如,如果它尝试绑定到端口 80(默认),您将看到:

    nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
    

    密切关注这些错误,它应该提供一些见解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      • 2013-06-18
      • 1970-01-01
      • 2015-09-15
      • 2022-01-03
      相关资源
      最近更新 更多