[Ngnix] connect() failed (111: Connection refused) while connecting to upstream.

N'CHE·2021년 12월 3일
1


증상

  • 502 Bad Gateway
  • [error] connect() failed (111: Connection refused)

원인

  • ⚠ 설정한 port가 열려있지 않아 발생한 오류.

해결

1. java spring boot project의 설정 port를 확인합니다.

application.properties

server.address=127.0.0.1
server.port=8000
~~

2. nginx config를 확인합니다.

sudo vi /etc/nginx/conf.d/www.conf
server
{
  server_name  some.name;

  listen  80;
  listen  443;

  ssl_certificate_key /etc/nginx/ssl-key/some.private.key;
  ssl_certificate /etc/nginx/ssl-key/some.crt;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers  HIGH:!aNULL:!MD5;

  location /
  {
    proxy_pass http://127.0.0.1:8080;
  }
}

listening port 80
proxy port 8080

3. nginx에서 설정한 port가 열려있는지 확인합니다.

sudo netstat -plant | grep '80'
sudo netstat -plant | grep '8080'
sudo netstat -plant | grep '8000'

저의 경우

java spring boot project의 설정 포트 8000이 열려있고, nginx에서 설정한 proxy port 8080과 상이하여 nginx config의 proxy port를 java의 설정과 맞게 8000으로 수정하여 해결했습니다.

1개의 댓글

comment-user-thumbnail
2023년 7월 19일

해결됐습니다 너무 감사합니다ㅠㅠ

답글 달기