0

I'm trying run the frontend (react) and a backend (nodejs, express) from a same ubuntu 20.4` machine but for some reason my nginx is not mapping correctly. I don't know if I have a typo somewhere or just configured something wrong?

Inside /etc/nginx/sites-enabled/ I have created 2 files one for the frontend and one for the backend

The contents inside the backend file are the following:

 server {
    # server_name  ## add server name
      server_name  backend.develop.mysite.be; // Dummy name for SO, but actual file contains the right address 

    location / {
        proxy_read_timeout 1800;
        proxy_connect_timeout 1800;
        proxy_send_timeout 1800;
        send_timeout 1800;

      proxy_pass http://localhost:9000;  // [ASK]: Is this is what is causing the problem? Maybe I should change it to 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;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/frontend.develop.mysite.be/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/frontend.develop.mysite.be/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
 server {
    if ($host = backend.develop.mysite.be) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
      server_name  backend.develop.mysite.be;
    return 404; # managed by Certbot


}

the contents for the frontend are very similar just with a different name. In the past this setup worked for me, but for some reason right now I'm getting a 502 BAD Gateway response error but only for the backend. The frontend seems to work just fine.

1
  • This has nothing to do with DevOps - maybe Server Fault is a better site for this question? – Mikael Dúi Bolinder Nov 19 '20 at 0:56
0

Never mind, I just figured it out 🙃. I just needed to change the port i was refering inside the backend file /etc/nginx/sites-enabled/backend

Changed this line proxy_pass http://localhost:9000; to this line proxy_pass http://localhost:3000; and it worked.

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