🌑

帮帮技术站

nextjs静态导出

静态导出 unoptimized 必须关闭 (静态导出会使依赖服务端的功能无法使用)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
basePath: '',
output: 'export',//out
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
trailingSlash: true,
// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
skipTrailingSlashRedirect: true,
// Optional: Change the output directory `out` -> `dist`
distDir: 'out',
images: {
unoptimized: true,
},
}

module.exports = nextConfig

nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
listen 80;
server_name lh.bbbang.com;

root D:/workspace-nextjs/simple-app/out;

location / {
try_files $uri $uri/ /index.html;
}

error_page 404 /404.html;

location = /404.html {
internal;
}
}

— Dec 10, 2023

Search