为什么我的上游是本地主机?Nginx 出现 500 错误,但没有应用程序错误。“连接到上游时没有实时上游”

为什么我的上游是本地主机?Nginx 出现 500 错误,但没有应用程序错误。“连接到上游时没有实时上游”

我正在跟进本教程使用 Nginx 在 CentOS 上托管 React 应用程序。当我运行 时,网站可以正常工作(200 个响应)curl localhost:3000,但是当我尝试他的anthurie.com我收到 500 错误,并且此错误/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/"

我不知道为什么upstream: "https://localhost/"大多数时候应用程序都处于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

}
                                                                                                                                                                                    

我正在此服务器上运行一个具有类似 nginx 配置的 Java 网站。应用程序运行正常,但我不知道为什么会出现 500 错误。

$ 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

答案1

https尝试用这里替换http

proxy_pass https://localhost:3000;

并重新加载 nginx。您说这curl localhost:3000有效,并且省略 curl 的协议假定http://。很可能您的后端应用程序不支持 HTTPS(或至少不支持此端口)。

相关内容