今晚我遇到了同样的问题。看完所有地方后,我发现了所需的配置。 env变量需要像下面一样进入您的def tf(corp):
words_set = set()
for i in corp:
a=i.split(' ')
for j in a:
words_set.add(j)
words_dict = {i:0 for i in words_set}
wcount=0
matr=list()
for doc in corp:
for worduni in words_dict:
count=0
for words in doc.split(' '):
if words==worduni:
count+=1
words_dict[worduni]=count/len(doc.split(' '))
print(words_dict)
matr.append(words_dict.copy())
return matr
。就我而言,我将其放在服务器的根目录
ecosystem.config.js
module.exports = {
apps : [{
name: 'nextjs',script: 'yarn',args:"start",cwd:"/var/www/myapp/",instances: 2,autorestart: true,watch: false,max_memory_restart: '1G',env: {
NODE_ENV: 'development'
},env_production: {
NODE_ENV: 'production',API_URL: 'YOUR ENV URL',PORT:8000
}
}]
};
package.json
并执行了类似的操作
"scripts": {
"dev": "next","build": "next build","start": "next start -p 8000"
},...
然后#!/bin/bash
cd /var/www/myapp/
git pull && yarn install && yarn build
cd ~/
pm2 start ecosystem.config.js --env production
将在您的应用程序中的API_URL
中可用。
这些网址有助于
https://willandskill.se/en/setup-a-next-js-project-with-pm2-nginx-and-yarn-on-ubuntu-18-04/
https://pm2.keymetrics.io/docs/usage/application-declaration/
,
另一个想法是通过以下方式将 PM2 的env
参数所有传递到服务器。
ecosystem.config.js
是:
module.exports = {
apps: [{
name: "my-service-1",script: "dist/server.js",env_production: process.env,// pass all the env params of the container to node
}],};
,
@webface
您示例中的环境变量在 Nextjs 中不可用。要对客户端和服务器都可用,变量必须以 NEXT_PUBLIC 为前缀(即 NEXT_PUBLIC_API_VERSION)。
这些环境变量必须传递到构建过程中才能在运行时可用。
本文链接:https://www.f2er.com/3136193.html