简体   繁体   English

503服务不可用。 服务器暂时繁忙,稍后再试! (下一个.js)

[英]503 Service Unavailable. The server is temporarily busy, try again later! (next.js)

I have a project using next.js and I try to deploy it on cpanel.我有一个使用 next.js 的项目,我尝试将它部署在 cpanel 上。 I've created web application in node.js and installed npm.我在 node.js 中创建了 Web 应用程序并安装了 npm。 Now when I try to open my website I receive this error:现在,当我尝试打开我的网站时,我收到此错误:

503 Service Unavailable. 503服务不可用。 The server is temporarily busy, try again later!服务器暂时繁忙,稍后再试!

here is my web application in node.js:这是我在 node.js 中的 Web 应用程序: 在此处输入图像描述

online-shop folder in cpanel: cpanel中的在线商店文件夹:

在此处输入图像描述

server.js: server.js:

// server.js
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const hostname = 'localhost'
const port = process.env.PORT || 3000
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer(async (req, res) => {
    try {
      // Be sure to pass `true` as the second argument to `url.parse`.
      // This tells it to parse the query portion of the URL.
      const parsedUrl = parse(req.url, true)
      const { pathname, query } = parsedUrl

      if (pathname === '/a') {
        await app.render(req, res, '/a', query)
      } else if (pathname === '/b') {
        await app.render(req, res, '/b', query)
      } else {
        await handle(req, res, parsedUrl)
      }
    } catch (err) {
      console.error('Error occurred handling', req.url, err)
      res.statusCode = 500
      res.end('internal server error')
    }
  }).listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://${hostname}:${port}`)
  })
})

package.json:包.json:

{
  "name": "next-project",
  "version": "0.1.0",
  "private": true,
  
 "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^6.1.1",
    "@fortawesome/free-regular-svg-icons": "^6.1.1",
    "@fortawesome/free-solid-svg-icons": "^6.1.1",
    "@fortawesome/react-fontawesome": "^0.1.18",
    "@popperjs/core": "^2.11.5",
    "@types/react-redux": "^7.1.24",
    "axios": "^0.27.2",
    "babel-plugin-macros": "^3.1.0",
    "bootstrap": "^5.1.3",
    "heroku": "^7.60.2",
    "jquery": "^3.6.0",
    "next": "12.1.5",
    "nextjs-progressbar": "0.0.14",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-loading": "^2.0.3",
    "react-redux": "^8.0.1",
    "redux": "^4.2.0",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.4.1",
    "sass": "^1.51.0",
    "vercel": "^24.2.5",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@types/node": "17.0.25",
    "@types/react": "18.0.6",
    "@types/react-dom": "18.0.2",
    "eslint": "8.14.0",
    "eslint-config-next": "12.1.5",
    "gh-pages": "^4.0.0",
    "typescript": "4.6.3"
  }
}

I tried to use another way : using _app page as startup file instead of server.js, but it also doesn't work!我尝试使用另一种方式:使用_app页面作为启动文件而不是server.js,但它也不起作用!

Update:更新:

I wrote console.log(process.env.PORT) and It was undefined!我写了 console.log(process.env.PORT) 它是未定义的! when I try console.log(process.env.PORT) and I receive this:当我尝试 console.log(process.env.PORT) 并收到以下信息时:

{
  ALLUSERSPROFILE: 'C:\\ProgramData',
  APPDATA: 'C:\\Users\\bamdad\\AppData\\Roaming',
  ChocolateyInstall: 'C:\\ProgramData\\chocolatey',
  CHROME_CRASHPAD_PIPE_NAME: '\\\\.\\pipe\\crashpad_4140_AHYPIDBZJEEXXFLL',
  COLORTERM: 'truecolor',
  CommonProgramFiles: 'C:\\Program Files\\Common Files',
  'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files',
  CommonProgramW6432: 'C:\\Program Files\\Common Files',
  COMPUTERNAME: 'DESKTOP-MJ4O8KO',
  ComSpec: 'C:\\Windows\\system32\\cmd.exe',
  DriverData: 'C:\\Windows\\System32\\Drivers\\DriverData',
  GIT_ASKPASS: 'c:\\Users\\bamdad\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass.sh',
  HOME: 'C:\\Users\\bamdad',
  HOMEDRIVE: 'C:',
  HOMEPATH: '\\Users\\bamdad',
  INIT_CWD: 'E:\\online-shop-next-js',
  LANG: 'en_US.UTF-8',
  LOCALAPPDATA: 'C:\\Users\\bamdad\\AppData\\Local',
  LOGONSERVER: '\\\\DESKTOP-MJ4O8KO',
  NODE: 'C:\\Program Files\\nodejs\\node.exe',
  NODE_EXE: 'C:\\Program Files\\nodejs\\\\node.exe',
  NPM_CLI_JS: 'C:\\Program Files\\nodejs\\\\node_modules\\npm\\bin\\npm-cli.js',
  npm_config_access: '',
  npm_config_allow_same_version: '',
  npm_config_also: '',
  npm_config_always_auth: '',
  npm_config_argv: '{"remain":[],"cooked":["run","dev"],"original":["run","dev"]}',
  npm_config_audit: 'true',
  npm_config_audit_level: 'low',
  npm_config_auth_type: 'legacy',
  npm_config_before: '',
  npm_config_bin_links: 'true',
  npm_config_browser: '',
  npm_config_ca: '',
  npm_config_cache: 'C:\\Users\\bamdad\\AppData\\Roaming\\npm-cache',
  npm_config_cache_lock_retries: '10',
  npm_config_cache_lock_stale: '60000',
  npm_config_cache_lock_wait: '10000',
  npm_config_cache_max: 'Infinity',
  npm_config_cache_min: '10',
  npm_config_cafile: '',
  npm_config_cert: '',
  npm_config_cidr: '',
  npm_config_color: 'true',
  npm_config_commit_hooks: 'true',
  npm_config_depth: 'Infinity',
  npm_config_description: 'true',
  npm_config_dev: '',
  npm_config_dry_run: '',
  npm_config_editor: 'notepad.exe',
  npm_config_engine_strict: '',
  npm_config_fetch_retries: '2',
  npm_config_fetch_retry_factor: '10',
  npm_config_fetch_retry_maxtimeout: '60000',
  npm_config_fetch_retry_mintimeout: '10000',
  npm_config_force: '',
  npm_config_format_package_lock: 'true',
  npm_config_fund: 'true',
  npm_config_git: 'git',
  npm_config_git_tag_version: 'true',
  npm_config_global: '',
  npm_config_globalconfig: 'C:\\Users\\bamdad\\AppData\\Roaming\\npm\\etc\\npmrc',
  npm_config_globalignorefile: 'C:\\Users\\bamdad\\AppData\\Roaming\\npm\\etc\\npmignore',
  npm_config_global_style: '',
  npm_config_group: '',
  npm_config_ham_it_up: '',
  npm_config_heading: 'npm',
  npm_config_https_proxy: '',
  npm_config_if_present: '',
  npm_config_ignore_prepublish: '',
  npm_config_ignore_scripts: '',
  npm_config_init_author_email: '',
  npm_config_init_author_name: '',
  npm_config_init_author_url: '',
  npm_config_init_license: 'ISC',
  npm_config_init_module: 'C:\\Users\\bamdad\\.npm-init.js',
  npm_config_init_version: '1.0.0',
  npm_config_json: '',
  npm_config_key: '',
  npm_config_legacy_bundling: '',
  npm_config_link: '',
  npm_config_local_address: '',
  npm_config_loglevel: 'notice',
  npm_config_logs_max: '10',
  npm_config_long: '',
  npm_config_maxsockets: '50',
  npm_config_message: '%s',
  npm_config_metrics_registry: 'https://registry.npmjs.org/',
  npm_config_node_gyp: 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
  npm_config_node_options: '',
  npm_config_node_version: '14.17.2',
  npm_config_noproxy: '',
  npm_config_offline: '',
  npm_config_onload_script: '',
  npm_config_only: '',
  npm_config_optional: 'true',
  npm_config_otp: '',
  npm_config_package_lock: 'true',
  npm_config_package_lock_only: '',
  npm_config_parseable: '',
  npm_config_prefer_offline: '',
  npm_config_prefer_online: '',
  npm_config_prefix: 'C:\\Users\\bamdad\\AppData\\Roaming\\npm',
  npm_config_preid: '',
  npm_config_production: '',
  npm_config_progress: 'true',
  npm_config_proxy: '',
  npm_config_read_only: '',
  npm_config_rebuild_bundle: 'true',
  npm_config_registry: 'https://registry.npmjs.org/',
  npm_config_rollback: 'true',
  npm_config_save: 'true',
  npm_config_save_bundle: '',
  npm_config_save_dev: '',
  npm_config_save_exact: '',
  npm_config_save_optional: '',
  npm_config_save_prefix: '^',
  npm_config_save_prod: '',
  npm_config_scope: '',
  npm_config_scripts_prepend_node_path: 'warn-only',
  npm_config_script_shell: '',
  npm_config_searchexclude: '',
  npm_config_searchlimit: '20',
  npm_config_searchopts: '',
  npm_config_searchstaleness: '900',
  npm_config_send_metrics: '',
  npm_config_shell: 'C:\\Windows\\system32\\cmd.exe',
  npm_config_shrinkwrap: 'true',
  npm_config_sign_git_commit: '',
  npm_config_sign_git_tag: '',
  npm_config_sso_poll_frequency: '500',
  npm_config_sso_type: 'oauth',
  npm_config_strict_ssl: 'true',
  npm_config_tag: 'latest',
  npm_config_tag_version_prefix: 'v',
  npm_config_timing: '',
  npm_config_tmp: 'C:\\Users\\bamdad\\AppData\\Local\\Temp',
  npm_config_umask: '0000',
  npm_config_unicode: '',
  npm_config_unsafe_perm: 'true',
  npm_config_update_notifier: 'true',
  npm_config_usage: '',
  npm_config_user: '',
  npm_config_userconfig: 'C:\\Users\\bamdad\\.npmrc',
  npm_config_user_agent: 'npm/6.14.13 node/v14.17.2 win32 x64',
  npm_config_version: '',
  npm_config_versions: '',
  npm_config_viewer: 'browser',
  npm_execpath: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
  npm_lifecycle_event: 'dev',
  npm_lifecycle_script: 'node server.js',
  npm_node_execpath: 'C:\\Program Files\\nodejs\\node.exe',
  npm_package_dependencies_axios: '^0.27.2',
  npm_package_dependencies_bootstrap: '^5.1.3',
  npm_package_dependencies_debug: '^4.3.1',
  npm_package_dependencies_heroku: '^7.60.2',
  npm_package_dependencies_jquery: '^3.6.0',
  npm_package_dependencies_next: '12.1.5',
  npm_package_dependencies_nextjs_progressbar: '0.0.14',
  npm_package_dependencies_react: '18.0.0',
  npm_package_dependencies_react_dom: '18.0.0',
  npm_package_dependencies_react_loading: '^2.0.3',
  npm_package_dependencies_react_redux: '^8.0.1',
  npm_package_dependencies_redux: '^4.2.0',
  npm_package_dependencies_redux_persist: '^6.0.0',
  npm_package_dependencies_redux_thunk: '^2.4.1',
  npm_package_dependencies_sass: '^1.51.0',
  npm_package_dependencies_vercel: '^24.2.5',
  npm_package_dependencies_yup: '^0.32.11',
  npm_package_dependencies__fortawesome_fontawesome_svg_core: '^6.1.1',
  npm_package_dependencies__fortawesome_free_regular_svg_icons: '^6.1.1',
  npm_package_dependencies__fortawesome_free_solid_svg_icons: '^6.1.1',
  npm_package_dependencies__fortawesome_react_fontawesome: '^0.1.18',
  npm_package_dependencies__popperjs_core: '^2.11.5',
  npm_package_dependencies__types_react_redux: '^7.1.24',
  npm_package_description: 'This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).',
  npm_package_devDependencies_eslint: '8.14.0',
  npm_package_devDependencies_eslint_config_next: '12.1.5',
  npm_package_devDependencies_gh_pages: '^4.0.0',
  npm_package_devDependencies_typescript: '4.6.3',
  npm_package_devDependencies__types_node: '17.0.25',
  npm_package_devDependencies__types_react: '18.0.6',
  npm_package_devDependencies__types_react_dom: '18.0.2',
  npm_package_homepage: 'https://bamdadghoori.github.io/nextjs-shopping',
  npm_package_name: 'next-project',
  npm_package_private: 'true',
  npm_package_readmeFilename: 'README.md',
  npm_package_scripts_build: 'next build',
  npm_package_scripts_dev: 'node server.js',
  npm_package_scripts_start: 'NODE_ENV=production node server.js',
  npm_package_version: '0.1.0',
  NPM_PREFIX_NPM_CLI_JS: 'C:\\Users\\bamdad\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
  NUMBER_OF_PROCESSORS: '4',
  OneDrive: 'C:\\Users\\bamdad\\OneDrive',
  ORIGINAL_XDG_CURRENT_DESKTOP: 'undefined',
  OS: 'Windows_NT',
  Path: 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\npm-lifecycle\\node-gyp-bin;E:\\online-shop-next-js\\node_modules\\.bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files\\Git\\cmd;C:\\xampp\\php;C:\\ProgramData\\ComposerSetup\\bin;C:\\Program Files (x86)\\AMD\\ATI.ACE\\Core-Static;C:\\Program Files\\nodejs\\;C:\\Users\\bamdad\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\bamdad\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\bamdad\\AppData\\Roaming\\Composer\\vendor\\bin;C:\\Users\\bamdad\\AppData\\Roaming\\npm',
  PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL',
  PROCESSOR_ARCHITECTURE: 'AMD64',
  PROCESSOR_IDENTIFIER: 'Intel64 Family 6 Model 37 Stepping 5, GenuineIntel',
  PROCESSOR_LEVEL: '6',
  PROCESSOR_REVISION: '2505',
  ProgramData: 'C:\\ProgramData',
  ProgramFiles: 'C:\\Program Files',
  'ProgramFiles(x86)': 'C:\\Program Files (x86)',
  ProgramW6432: 'C:\\Program Files',
  PROMPT: '$P$G',
  PSExecutionPolicyPreference: 'Bypass',
  PSModulePath: 'C:\\Users\\bamdad\\Documents\\WindowsPowerShell\\Modules;C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
  PUBLIC: 'C:\\Users\\Public',
  SystemDrive: 'C:',
  SystemRoot: 'C:\\Windows',
  TEMP: 'C:\\Users\\bamdad\\AppData\\Local\\Temp',
  TERM_PROGRAM: 'vscode',
  TERM_PROGRAM_VERSION: '1.69.0',
  TMP: 'C:\\Users\\bamdad\\AppData\\Local\\Temp',
  USERDOMAIN: 'DESKTOP-MJ4O8KO',
  USERDOMAIN_ROAMINGPROFILE: 'DESKTOP-MJ4O8KO',
  USERNAME: 'bamdad',
  USERPROFILE: 'C:\\Users\\bamdad',
  VSCODE_GIT_ASKPASS_EXTRA_ARGS: '--ms-enable-electron-run-as-node',
  VSCODE_GIT_ASKPASS_MAIN: 'c:\\Users\\bamdad\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\extensions\\git\\dist\\askpass-main.js',
  VSCODE_GIT_ASKPASS_NODE: 'C:\\Users\\bamdad\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe',
  VSCODE_GIT_IPC_HANDLE: '\\\\.\\pipe\\vscode-git-4082b97ab1-sock',
  windir: 'C:\\Windows'
}

It seems process.env doesn't have PORT property!why?似乎 process.env 没有 PORT 属性!为什么?

Finally, I solved my problem by changing the node version of web application in cpanel.最后,我通过在 cpanel 中更改 web 应用程序的节点版本解决了我的问题。 In fact, the problem was that I was using node version 10.24 in cpanel and version 14.17 on my local machine!事实上,问题在于我在 cpanel 中使用的是节点版本 10.24,而在我的本地机器上使用的是版本 14.17!

So I changed node.js version in cpanel to 14.18.3(the closest to my local version) and it worked!所以我将 cpanel 中的 node.js 版本更改为 14.18.3(最接近我的本地版本)并且它工作了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM