Jenkins returns 502 gateway error and (104: Connection reset by peer) So my server got maintenance schedule from cloud provider, after maintenance process, the server rebooted, then my jenkins cannot be accessed from the web anymore, I am using nginx and checking the logs I found this.


  /var/log/nginx/error.log


2018/03/26 16:11:00 [error] 21689#21689: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 139.139.139.139, server: jenkins.domain.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "jenkins.domain.com"

2018/03/26 16:11:00 [error] 21689#21689: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 139.139.139.139, server: jenkins.domain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8080/favicon.ico", host: "jenkins.domain.com", referrer: "http://jenkins.domain.com/"


here is my nginx conf file:

upstream app_server {
server 127.0.0.1:8080 fail_timeout=0;
}



server {
  listen 80;
  server_name jenkins.domain.com;
  root /var/www/jenkins.domain.com;

  location ~ /\.well-known/acme-challenge {
        default_type "text/plain";
  }

  location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://app_server;
            break;
        }
    }
}


What is the cause of this and maybe what can I do to fix this? Really need your help guys.

Thanks
If the system recently rebooted and your proxy server is giving 502/503s, it's most likely that the backend service failed to start.

Using whatever tools are most appropriate for your OS/distro (e.g. systemctl, service/chkconfig, stop/start/restart/etc.), do the following things:


Verify that the backend (in this case Jenkins) is configured to start on boot.  Enable it if not.
Start the backend.
If the backend fails to start, check the application logs to find the source of the error.  For Jenkins on Linux, this would be /var/log/jenkins/jenkins.log.