Score:0

Why is my upstream localhost? Getting 500 but no app error in Nginx. " no live upstreams while connecting to upstream"

cn flag

I'm following this tutorial to host a React app on CentOS using Nginx. The website works (200 response) when I run curl localhost:3000, but when I try to his anthurie.com I get 500 error and this error in /var/log/nginx/error.log

2021/10/17 17:56:16 [error] 5379#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: anthurie.com, request: "GET / HTTP/1.1", upstream: "https://[::1]:3000/", host: "anthurie.com"
2021/10/17 17:56:16 [error] 5379#0: *5 SSL_do_handshake() failed (SSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol) while SSL handshaking to upstream, client: 192.168.1.1, server: anthurie.com, request: "GET / HTTP/1.1", upstream: "https://127.0.0.1:3000/", host: "anthurie.com"
2021/10/17 17:56:17 [error] 5379#0: *5 no live upstreams while connecting to upstream, client: 192.168.1.1, server: anthurie.com, request: "GET /favicon.ico HTTP/1.1", upstream: "https://localhost/favicon.ico", host: "anthurie.com", referrer: "https://anthurie.com/"
2021/10/17 18:01:01 [error] 5379#0: *9 no live upstreams while connecting to upstream, client: 192.168.1.1, server: anthurie.com, request: "GET / HTTP/1.1", upstream: "https://localhost/", host: "anthurie.com"
2021/10/17 18:01:02 [error] 5379#0: *9 no live upstreams while connecting to upstream, client: 192.168.1.1, server: anthurie.com, request: "GET /favicon.ico HTTP/1.1", upstream: "https://localhost/favicon.ico", host: "anthurie.com", referrer: "https://anthurie.com/"

Idk why it has upstream: "https://localhost/" most of the time the app is at localhost:3000

/etc/systemd/system/anthurie.service

[Unit]
Description=Service run for reactjs application anthurie.com
After=network.target

[Service]
Type=simple
User=prego
Group=nginx
StandardOutput=syslog
StandardError=syslog
WorkingDirectory=/var/metaplex/js
Environment=NODE_ENV=’production’
ExecStart=/usr/bin/yarn start
Restart=always

[Install]
WantedBy=multi-user.target

nginx.conf

    server {
        proxy_read_timeout 10m;
        server_name anthurie.com;

        #a special location in case don't cache this file can be deleted
        location updater/serversettings.xml {
          expires -1;
          add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
        }

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #The root/rest will be redirected
        location / {
            proxy_cache             hd_cache;
            proxy_set_header        X-Cache-Status $upstream_cache_status;
            proxy_cache_valid       200 1w;
            proxy_pass              https://localhost:3000;
            proxy_set_header        Host $http_host;
            proxy_buffers           16 8m;
            proxy_buffer_size       2m;
            gzip                    on;
            gzip_vary               on;
            gzip_comp_level         9;
            gzip_proxied            any;
        }
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }


        listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/anthurie.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/anthurie.com/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

}
                                                                                                                                                                                    

I'm running a Java website with a similiar nginx config on this server. Not sure why I'm getting 500 when app appears to be running fine.

$ sudo systemctl status anthurie
● anthurie.service - Service run for reactjs application anthurie.com
   Loaded: loaded (/etc/systemd/system/anthurie.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-10-17 17:26:48 EDT; 49min ago
 Main PID: 4908 (node)
   CGroup: /system.slice/anthurie.service
           ├─4908 node /usr/share/yarn/bin/yarn.js start
           ├─4929 /usr/bin/node /var/metaplex/js/node_modules/.bin/cross-env CI=true lerna run start --scope @oyster/common --stream --parallel --scope web
           ├─4936 /usr/bin/node /var/metaplex/js/node_modules/.bin/lerna run start --scope @oyster/common --stream --parallel --scope web
           ├─4950 node /usr/share/yarn/bin/yarn.js run start
           ├─4961 node /usr/share/yarn/bin/yarn.js run start
           ├─4992 /usr/bin/node /var/metaplex/js/node_modules/.bin/npm-run-all --parallel watch watch-css watch-css-src
           ├─5010 /usr/bin/node /var/metaplex/js/packages/web/node_modules/.bin/next dev
           ├─5016 /usr/bin/node /usr/share/yarn/bin/yarn.js run watch
           ├─5017 /usr/bin/node /usr/share/yarn/bin/yarn.js run watch-css
           ├─5023 /usr/bin/node /usr/share/yarn/bin/yarn.js run watch-css-src
           ├─5061 /usr/bin/node /var/metaplex/js/node_modules/.bin/tsc --watch
           ├─5071 /usr/bin/node /home/prego/.yarn/bin/less-watch-compiler src/ src/
           ├─5079 /usr/bin/node /home/prego/.yarn/bin/less-watch-compiler src/ dist/lib/
           └─5255 /usr/bin/node /var/metaplex/js/node_modules/next/node_modules/jest-worker/build/workers/processChild.js

Oct 17 17:27:12 localhost.localdomain yarn[4908]: @oyster/common:         Property 'Bitpie' is missing in type 'import("/var/metaplex/js/node_modules/@solana/wallet-adapter-react/node_mo....WalletName'.
Oct 17 17:27:12 localhost.localdomain yarn[4908]: @oyster/common: src/contexts/wallet.tsx(230,3): error TS2344: Type '"publicKey" | "signTransaction" | "signAllTransactions"' does not sa...vents, any>'.
Oct 17 17:27:12 localhost.localdomain yarn[4908]: @oyster/common:   Type '"signTransaction"' is not assignable to type 'keyof WalletAdapterProps | keyof EventEmitter<WalletAdapterEvents, any>'.
Oct 17 17:27:12 localhost.localdomain yarn[4908]: @oyster/common: src/contracts/token.ts(106,23): error TS2571: Object is of type 'unknown'.
Oct 17 17:27:12 localhost.localdomain yarn[4908]: @oyster/common: 5:27:12 PM - Found 7 errors. Watching for file changes.
Oct 17 17:27:56 localhost.localdomain yarn[4908]: web: event - build page: /
Oct 17 17:27:56 localhost.localdomain yarn[4908]: web: wait  - compiling...
Oct 17 17:28:02 localhost.localdomain yarn[4908]: web: event - compiled successfully
Oct 17 17:29:04 localhost.localdomain yarn[4908]: web: wait  - compiling...
Oct 17 17:29:04 localhost.localdomain yarn[4908]: web: event - compiled successfully
Score:1
de flag

Try to replace https with http here:

proxy_pass https://localhost:3000;

and reload nginx. You said that curl localhost:3000 worked, and omitting a protocol for curl assumes http://. Most probably, your backend application does not support HTTPS (or not at this port, at least).

cn flag
Thanks a bunch it's loading now.
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.