0

I'm deploying my project, I had no problem until i decided to buy a domain for my digital ocean droplet i added the records from my namecheap domain to my droplet i was working on it then suddenly when i want access to myproject/api it's now showing 502 errors i'll give you all the informations so maybe you can help me with it

1 ) mongoDB atlas status : All good ; i even tried " npm start " to see if DB can't connect but it connects perfectly fine. I refreshed in .env the connecting string, it stills connect with no problems.

2 ) Nginx error.log shows this information i don't really understand, i guess it's the key point : 86 connect() failed (111: Connection refused) while connecting to upstream, client: 164.92.206.160, server: _, request: "GET /api/category/cinema HTTP/1.1", upstream: "http://[::1]:8000/api

3 ) The front is perfectly showing himself on my project domain url it starts showing 502 error when i click something using my DB/server.

4 ) i rebuilded and restarted front & back + nginx multiple times

5 ) i updated endpoints and .env variables to match with my fresh domain and it works, only the API side is breaking

6 ) nginx conf file :

server {
        listen 80 default_server;
        listen [::]:80 default_server;

      

        root /var/www/html;


        server_name _;

        location /api {
    proxy_pass http://localhost:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

I tried barely everything and it's still not working as it was used to work.

1 Answers1

1

As the linked thread indicated in comment, probably your upstream server isn't listening at http://[::1]:8000.

Note that [::1] is the IPv6 loopback address (like 127.0.0.1 for IPv4), so if the upstream is IPv4 only, you should explicitly write 127.0.0.1 in config file, instead of localhost.

Lex Li
  • 1,235
  • 8
  • 10
  • Sounds like a solution, i'm real newbie, where i'm supposed to write your suggestion in my conf file ? Thanks for trying to help me tho – Harkayn Jan 06 '23 at 20:41
  • proxy_pass http://localhost:8000 into proxy_pass http://127.0.0.1 ? or into proxy_pass http://164.92.206.160 ? Or shall i activate Ipv6 on my digital ocean droplet and use the Ipv6 adress ? – Harkayn Jan 06 '23 at 20:45
  • You might get started from `127.0.0.1:8000`. If it works, then you don't really need further changes like activating IPv6 on droplet. – Lex Li Jan 06 '23 at 20:52
  • I get it i think so but i have no idea where i'm supposed to enter this new value ? By replacing this line ? proxy_pass localhost:8000 ? Like proxy_pass 127.0.0.1:8000 ? – Harkayn Jan 06 '23 at 21:09
  • Yes, replace `proxy_pass localhost:8000` with `proxy_pass 127.0.0.1:8000`. – Lex Li Jan 06 '23 at 21:43
  • Thanks a lot, i'll try out the solution asap and comeback to tell you if it worked – Harkayn Jan 07 '23 at 00:19
  • Not working with 127.0.0.1:8000 i try with 164.92.206.160:8000 error code : ''' 25 connect() failed (111: Connection refused) while connecting to upstream, client: 164.92.206.160, server: _, request: "GET /api/category/cinema HTTP/1.1", upstream: "http://127.0.0.1:8000/api/category/cinema", host: "164.92.206.160 ''' – Harkayn Jan 07 '23 at 12:22
  • not working either with 164.92.206.160:8000 error code : 4 connect() failed (111: Connection refused) while connecting to upstream, client: 164.92.206.160, server: _, request: "GET /api/category/cinema HTTP/1.1", upstream: "http://164.92.206.160:8000/api/category/cinema", host: "164.92.206.160 – Harkayn Jan 07 '23 at 12:30
  • @Harkayn then the information provided by you in the question body is incorrect. How exactly did you configure the upstream server? Edit the question to explain further and use `netstat` to analyze what port it listens on. – Lex Li Jan 07 '23 at 17:19
  • tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50389 tcp 0 0 SEOBLOG:50156 104.21.29.13:http tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50387 tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50390 tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50388 tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50391 tcp 0 0 SEOBLOG:http 4vg55-h01-176-133:50392 tcp6 0 736 SEOBLOG:ssh 162.243.190.66:33216 ESTABLISHED tcp6 0 0 SEOBLOG:ssh 162.243.190.66:33216 ESTABLISHED – Harkayn Jan 09 '23 at 10:39