Nginx
為什麼是我的上游本地主機?在 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
嘗試在這裡
https
替換http
:proxy_pass https://localhost:3000;
並重新載入 nginx。你說這
curl localhost:3000
行得通,並且省略 curl 的協議假設http://
. 很可能,您的後端應用程序不支持 HTTPS(或至少在此埠不支持)。