'NGINX - Setting up for react app and flask be with different port numbers

I have the react app to run on

www.domain.io:3000

And the Flask API is running on

www.domain.io:5000

The React app is shown when navigated to www.domain.io, but it's having trouble talking to the API on www.domain.io:5000.

How can I set the NGINX server block so the React app and Flask API can co-exist under www.domain.io?

Here is my server block

ssl_certificate /etc/letsencrypt/live/twitterlicious.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/twitterlicious.io/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{
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name twitterlicious.io www.twitterlicious.io;

        proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $remote_addr;

        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;
        }


        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot

}

server {
        listen 5000;
        location /{
                proxy_pass http://localhost:5000;
        }
}

server {
    if ($host = www.twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = twitterlicious.io) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server;

        server_name twitterlicious.io www.twitterlicious.io;
    return 404; # managed by Certbot

}

Any help is appreciated. Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source