在Heroku中部署应用程序时如何解决502 Bad Gateway错误

时间:2019-11-04 16:24:51

标签: nginx heroku

我只想在Heroku云中测试一个简单的HTML 1页面webapp。 Heroku和Nginx对我来说是新手 。 我使用了Nginx Buildpack,一旦部署了应用程序,我将收到502 Bad Gateway错误。

我试图检查日志并发现以下错误。

2019-11-04T15:29:27.937072+00:00 app[web.1]: 2019/11/04 15:29:27 [crit] 20#0: *14 connect() to unix:/tmp/nginx.socket failed (2: No such file or directory) while connecting to upstream, client: 10.5.179.3, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/tmp/nginx.socket:/favicon.ico", host: "someting.herokuapp.com", referrer: "https://someting.herokuapp.com/testpage_text.html"

/ tmp在服务器上。以下是默认配置。

daemon off;
#Heroku dynos have at least 4 cores.
worker_processes <%= ENV['NGINX_WORKERS'] || 4 %>;

events {
    use epoll;
    accept_mutex on;
    worker_connections <%= ENV['NGINX_WORKER_CONNECTIONS'] || 1024 %>;
}

http {
        gzip on;
        gzip_comp_level 2;
        gzip_min_length 512;

    server_tokens off;

    log_format l2met 'measure#nginx.service=$request_time request_id=$http_x_request_id';
    access_log <%= ENV['NGINX_ACCESS_LOG_PATH'] || 'logs/nginx/access.log' %> l2met;
    error_log <%= ENV['NGINX_ERROR_LOG_PATH'] || 'logs/nginx/error.log' %>;

    include mime.types;
    default_type application/octet-stream;
    sendfile on;

    #Must read the body in 5 seconds.
    client_body_timeout 5;

    upstream app_server {
        server unix:/tmp/nginx.socket fail_timeout=0;
    }

    server {
        listen <%= ENV["PORT"] %>;
        server_name _;
        keepalive_timeout 5;

        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
        }
    }
}

我是否需要在配置中更改或添加任何内容到“上游app_server”以使站点正常工作?

在此先感谢您的帮助!

0 个答案:

没有答案