<p>Never mind, I just figured it out . I just needed to change the port i was refering inside the <code>backend</code> file <code>/etc/nginx/sites-enabled/backend</code></p>
<p>Changed this line <code>proxy_pass http://localhost:9000;</code> to this line <code>proxy_pass http://localhost:3000;</code> and it worked.</p>

CC BY-SA 4.0
2020-11-17T16:38:30.177Z
2020-11-17T16:38:30.177Z
intercoder
<p>I'm trying run the frontend (<code>react</code>) and a backend (<code>nodejs, </code>express<code>) from a same </code>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?</p>
<p>Inside <code>/etc/nginx/sites-enabled/</code> I have created 2 files one for the <code>frontend</code> and one for the <code>backend</code></p>
<p>The contents inside the <code>backend</code> file are the following:</p>
<pre><code> 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


}
</code></pre>
<p>the contents for the <code>frontend</code> 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 <code>502 BAD Gateway</code> response error but only for the <code>backend</code>. The <code>frontend</code> seems to work just fine.</p>

CC BY-SA 4.0
2020-11-19T00:56:56.630Z
This has nothing to do with DevOps - maybe Server Fault is a better site for this question?
Mikael Dúi Bolinder
<nginx><node.js><ubuntu>
Getting a 502 Bad Server Request on Nginx
intercoder
# Getting a 502 Bad Server Request on Nginx

(Asked by: username_0 on 2020-11-17)

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.

**Tags:** nginx, node.js, ubuntu

> **Comments:**
> **username_1**: This has nothing to do with DevOps - maybe Server Fault is a better site for this question?  

---

## 1 answers

### Answer by username_0 on 2020-11-17. Score: 0 | Accepted answer

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.


---

