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

1 Answer 1

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.

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 6 at 20:41
  • proxy_pass localhost:8000 into proxy_pass 127.0.0.1 ? or into proxy_pass 164.92.206.160 ? Or shall i activate Ipv6 on my digital ocean droplet and use the Ipv6 adress ?
    – Harkayn
    Jan 6 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 6 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 6 at 21:09
  • Yes, replace proxy_pass localhost:8000 with proxy_pass 127.0.0.1:8000.
    – Lex Li
    Jan 6 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.