nginx 部署next编译的项目,解决403问题

2025-05-28  本文已影响0人  承诺一时的华丽
/** @type {import('next').NextConfig} */
const nextConfig = {
    output: 'export',
    experimental: {
        missingSuspenseWithCSRBailout: false,
    },
    eslint: {
        ignoreDuringBuilds: true,
    },
    typescript: {
        ignoreBuildErrors: true,
    },
    images: {
        unoptimized: true,
    },
    webpack: (config) => {
        config.module.rules.push({
            test: /(?<!\.next\/static).*\.txt$/, // 排除.next/static目录外的txt文件
            use: 'null-loader'
        });
        return config;
    },
    // 新增代理配置
    async rewrites() {
        if (process.env.NODE_ENV === 'development') {
            return {
                fallback: [
                    {
                        source: '/apiservice/:path*',
                        destination: 'http://127.0.0.1:1004/:path*', // 你的后端地址
                    },
                ],
            };
        }
        return [];
    }
}
export default nextConfig

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        # next 配置
        try_files $uri $uri.html /$uri /index.html;
        # vue 配置
        # try_files $uri $uri/ /index.html;
    }
上一篇 下一篇

猜你喜欢

热点阅读