如何在 cpanel 上部署 nextjs 应用程序?

Afs*_*fda 1 deployment .htaccess cpanel reactjs next.js

我按照这些步骤在 cPanel 上部署了我的 nextjs。

  1. 转到 package.json 并添加以下行: "homepage": "http://afsanefadaei.ir"

  2. 运行next build以将.next文件夹作为我的构建文件夹

  3. 转到cpanel >> file manager >> public_html文件夹并将文件夹的内容上传.next到此目录

  4. 添加或编辑此文件:.htaccess到:

    在此处输入图片说明

但是当我访问该网站时,我遇到了以下情况:

在此处输入图片说明

你知道这有什么问题吗?

Dar*_*ert 6

  1. .next没有index.html 文件。
  2. 似乎您有服务器端(主要使用 Nodejs),但不幸的是您无法从 cpanel 运行该服务器端。
  3. 据我所知,如果您倾向于仅使用前端,则应该使用next export而不是。next build

但最重要的是第一件事,确保你index.html的文件夹中有.next


小智 6

我上传out(它被生成npm run build && npm run export)文件夹到public_html并创建了.htaccess文件,如

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-L
  RewriteRule . /index.html [L]

</IfModule>
Run Code Online (Sandbox Code Playgroud)

它对我有用

问题:当我在一些不同的路线上刷新页面时,比方说/about,它带来了index.js页面内容,但 URL 不会更改为/