Score:0

my nginx server was working perfectly fine and now shows a 502 error

ms flag

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.

user9517 avatar
cn flag
https://serverfault.com/questions/725262/what-causes-the-connection-refused-message
Score:1
vn flag

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.

Harkayn avatar
ms flag
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 avatar
ms flag
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 ?
Lex Li avatar
vn flag
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.
Harkayn avatar
ms flag
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 ?
Lex Li avatar
vn flag
Yes, replace `proxy_pass localhost:8000` with `proxy_pass 127.0.0.1:8000`.
Harkayn avatar
ms flag
Thanks a lot, i'll try out the solution asap and comeback to tell you if it worked
Harkayn avatar
ms flag
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 avatar
ms flag
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
Lex Li avatar
vn flag
@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.
Harkayn avatar
ms flag
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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.