Heroku + docker + nginx每个请求返回500

时间:2017-05-21 10:35:39

标签: nginx heroku

我将docker容器部署到Heroku主机。 Container包含nginx和静态文件,由webpack在contains-build阶段创建。 根目录是/ data / www,包含index.html,style.css,style.css.map,bundle.js,vendor.bundle.js和带资源的目录(images / etc)

我的nginx conf:

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

1 个答案:

答案 0 :(得分: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)

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