502 Bad Gateway nginx / 1.10.3(Ubuntu)

时间:2017-12-17 15:18:24

标签: nginx

尝试部署用Rails和Angular编写的应用程序。

当我通过浏览器发送请求时,我在浏览器中收到502网关超时错误

当我检查日志时,我收到了这个错误:

2017/12/17 20:07:48 [error] 12347#12347: *1 connect() failed (113: No route to host) while connecting to upstream, client: 10.50.60.2, server: 10.12.4.245, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.12.4.245:80/favicon.ico", host: "10.12.4.242", referrer: "http://10.12.4.242/"

我该如何解决,请详细解释。

这是我的配置:

/etc/nginx/sites-available/nginx.conf:

 upstream puma {
  server unix:///var/www/phonebook-api/tmp/sockets/puma.sock;
}
server {
listen   80 default;
listen   [::]:80 default ipv6only=on;

server_name 10.12.4.245;
charset utf-8;
root /var/www/phonebook-api;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

location / {
root phonebook-app/dist;
index index.html index.htm;
try_files $uri @app;
        gzip_static on;
        expires max;
        proxy_read_timeout 150;
        add_header Cache-Control public;
  }
  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://puma;
  }
   location @app {
     proxy_pass        http://10.12.4.245;
     proxy_set_header  X-Real-IP  $remote_addr;
     proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header  X-Forwarded-Proto http;
     proxy_set_header  Host $http_host  ;
     proxy_redirect    off;
     proxy_next_upstream error timeout invalid_header http_502;
    }

  client_max_body_size 50M;
  keepalive_timeout 10;
}

2 个答案:

答案 0 :(得分:0)

打开#file settings.py

ALLOWED_HOSTS = [] 至 ALLOWED_HOSTS = [' www.btcdoller.com',' btcdoller.com',' 206.189.113.168']

发现我们的IP地址

ALLOWED_HOSTS = ip_addresses() 至 ALLOWED_HOSTS + = ip_addresses()

答案 1 :(得分:0)

这是因为您的app.js或index.js中存在错误,请首先尝试解决该问题,然后重试。