next js项目部署相同域名不同路径访问,使用客户端模式

1:创建项目安装官网步骤
npx create-next-app@latest

2:修改next.config.mjs配置文件

/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
    basePath: '/test',
};

export default nextConfig;

3:修改package.json配置文件


{
  "name": "uniweb-payment-link-frontend",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://merchant-stage.uniwebpay.com/test",
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "react": "^18",
    "react-dom": "^18",
    "next": "14.2.3"
  },
  "devDependencies": {
    "typescript": "^5",
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "eslint": "^8",
    "eslint-config-next": "14.2.3"
  }
}

4:更改page.tsx文件

'use client'
import Image from "next/image";
import Login from "./login";
import './globals.css'

export default function Home() {
  return (
    <main className="flex min-h-screen flex-col items-center justify-between p-24 bg-white">
       <Login/>
    </main>
  );
}

5:运行编译命定

npm ru build

6:把输出out文件放到nginx文件目录上/var/www/test/

7:修改nginx default配置文件

location /test {
alias /var/www/test/;
}

8:域名访问地址
https://xxx.xx.com/test

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容