The original post: /r/nginx by /u/Avry_great on 2024-11-29 10:54:05.

I’m trying to host my website for the first time and NGINX seem like it doesn’t recognize my backend. I tried to make the API location in NGINX to recognize all the APIs and send to port 5000 but doesn’t work so I decided to test a single API as above. Their are always an error message in the signup interface but there are nothing in the backend console or any POST/GET log printed out even tho it run perfectly fine in local. The error from NGINX log is: 2024/11/29 10:36:48 [error] 901#901: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 172.69.121.138, server: avery-insights.icu, request: “POST /auth/signup HTTP/1.1”, upstream: “http://127.0.0.1:5000/auth/signup”, host: “avery-insights.icu”

    location /auth/signup {
    proxy_pass http://localhost:5000/auth/signup;
    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;
}

Backend code:

server.js:

const authRoutes = require('./routes/authRoutes');
app.use('/auth', authRoutes);
app.use('/table', tableRoutes);

authRoutes.js

router.post('/signup', validateSignup, signup);