上线配置
打包上线
通过打包命令,将项目进行打包压缩生成 .output文件, 新建一个文件dist,把.output放进去
那么大家在上线的时候一定要切记,在打包之前先把接口请求的代理地址改为线上地址
例如配置文件:nuxt.config.ts
export default defineNuxtConfig({
//请求接口前缀设置
runtimeConfig: {
public: {
// 线上服务器地址
baseUrl: process.env.BASE_URL|| 'https://fastpros.lyqing.cn/shop',
}
}, '@pinia/nuxt',
],
//接口反向代理设置 线上服务器地址
vite: {
server: {
proxy: {
'/shop': {
target: 'https://fastpros.lyqing.cn/shop',
changeOrigin: true,
prependPath: true,
rewrite: (path) => path.replace(/^\/shop/, '')
}
}
}
},
})
然后运行打包命令
npm run build
最后传递到服务器上面,并配置服务器的反向代理
Nginx反向代理
server {
location /shop {
#需要代理的地址
proxy_pass https://fastpros.lyqing.cn/shop;
}
}