Egg: prod 启动报 500 错误

Created on 23 Feb 2017  ·  26Comments  ·  Source: eggjs/egg

  • Node Version: 6.9.4
  • Egg Version: 0.9.0
  • Plugin Name:
  • Plugin Version:
  • Platform: centos 7

日志显示是启动成功的, 但访问时出现: Internal Server Error, real status: 500

启动日志如下:

EGG_SERVER_ENV=prod node server
2017-02-23 22:01:36,513 INFO 24708 [master] =================== egg start =====================
2017-02-23 22:01:36,517 INFO 24708 [master] egg version 0.9.0
2017-02-23 22:01:36,518 INFO 24708 [master] start with options: {"customEgg":"/home/node-app/update-check-web-7001/node_modules/.0.9.0@egg","baseDir":"/home/node-app/update-check-web-7001","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":""}
2017-02-23 22:01:36,518 INFO 24708 [master] start with env: isProduction: true, isDebug: false, EGG_SERVER_ENV: prod, NODE_ENV: undefined
2017-02-23 22:01:36,535 INFO 24708 [master] Agent Worker:24714 start with ["{\"customEgg\":\"/home/node-app/update-check-web-7001/node_modules/.0.9.0@egg\",\"baseDir\":\"/home/node-app/update-check-web-7001\",\"port\":7001,\"workers\":1,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"clusterPort\":33900}"]
2017-02-23 22:01:37,045 INFO 24714 [egg:logger] init all loggers with options: {"dir":"/root/logs/egg-mhsq-app","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-mhsq-app-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"agent"}
2017-02-23 22:01:37,145 WARN 24714 [egg-watcher] defaultEventSource watcher will NOT take effect
2017-02-23 22:01:37,148 INFO 24714 [egg:agent] create an AgentWorkerClient for "watcher"
2017-02-23 22:01:37,557 INFO 24714 [egg-mongoose] connecting mongodb://172.16.0.90:27017/update-check
2017-02-23 22:01:37,763 INFO 24714 [egg-mongoose] starting...
2017-02-23 22:01:37,768 INFO 24714 [egg:watcher:agent] watcher start success
(node:24714) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2017-02-23 22:01:37,808 INFO 24714 [egg-mongoose] mongodb://172.16.0.90:27017/update-check connected successfully
2017-02-23 22:01:37,845 INFO 24714 [egg-mongoose] start successfully and server status is ok
2017-02-23 22:01:37,862 INFO 24708 [master] Agent Worker started (1338ms)
2017-02-23 22:01:37,873 INFO 24708 [master] App Worker#1:24724 start, state: none, current workers: ["1"]
2017-02-23 22:01:38,691 INFO 24724 [egg:logger] init all loggers with options: {"dir":"/root/logs/egg-mhsq-app","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-mhsq-app-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-02-23 22:01:38,695 INFO 24724 [egg:worker] create an AppWorkerClient for "watcher"
2017-02-23 22:01:38,749 INFO 24724 [egg-schedule]: register schedule egg-schedule:/home/node-app/update-check-web-7001/node_modules/.2.2.2@egg-logrotator/app/schedule/clean_log.js
2017-02-23 22:01:38,749 INFO 24724 [egg-schedule]: register schedule egg-schedule:/home/node-app/update-check-web-7001/node_modules/.2.2.2@egg-logrotator/app/schedule/rotate_by_file.js
2017-02-23 22:01:39,106 INFO 24724 [egg-mongoose] connecting mongodb://172.16.0.90:27017/update-check
2017-02-23 22:01:39,382 INFO 24724 [egg-static] starting static serve /public/ -> /home/node-app/update-check-web-7001/app/public
2017-02-23 22:01:39,389 INFO 24724 [egg-security] use csrf middleware
2017-02-23 22:01:39,390 INFO 24724 [egg-security] use methodnoallow middleware
2017-02-23 22:01:39,391 INFO 24724 [egg-security] use noopen middleware
2017-02-23 22:01:39,391 INFO 24724 [egg-security] use nosniff middleware
2017-02-23 22:01:39,392 INFO 24724 [egg-security] use xssProtection middleware
2017-02-23 22:01:39,393 INFO 24724 [egg-security] use xframe middleware
2017-02-23 22:01:39,393 INFO 24724 [egg-security] compose 6 middlewares into one security middleware
2017-02-23 22:01:39,484 INFO 24724 [egg-mongoose] starting...
(node:24724) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2017-02-23 22:01:39,528 INFO 24724 [egg-mongoose] mongodb://172.16.0.90:27017/update-check connected successfully
2017-02-23 22:01:39,580 INFO 24724 [egg-mongoose] start successfully and server status is ok
2017-02-23 22:01:39,595 WARN 24708 [master] App Worker#1:24724 started at 7001, remain 0 (1733ms)
2017-02-23 22:01:39,595 INFO 24708 [master] egg started on http://127.0.0.1:7001 (3076ms)

question

Most helpful comment

在 config.default.js 里面加入配置项:

exports.keys = 'your secret key';

里面填你的秘钥,这个在开发环境执行就有提示的,你一直没配。。

All 26 comments

看一下错误日志
天马行空 notifications@github.com于2017年2月23日 周四22:11写道:

>

  • Node Version: 6.9.4
  • Egg Version: 0.9.0
  • Plugin Name:
  • Plugin Version:
  • Platform: centos 7

日志显示是启动成功的, 但访问时出现: Internal Server Error, real status: 500

启动日志如下:

EGG_SERVER_ENV=prod node server

2017-02-23 22:01:36,513 INFO 24708 [master] =================== egg start

2017-02-23 22:01:36,517 INFO 24708 [master] egg version 0.9.0
2017-02-23 22:01:36,518 INFO 24708 [master] start with options:
{"customEgg":"/home/node-app/update-check-web-7001/node_modules/.0.9.0@egg
","baseDir":"/home/node-app/update-check-web-7001","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":""}
2017-02-23 22:01:36,518 INFO 24708 [master] start with env: isProduction:
true, isDebug: false, EGG_SERVER_ENV: prod, NODE_ENV: undefined
2017-02-23 22:01:36,535 INFO 24708 [master] Agent Worker:24714 start with
["{"customEgg":"/home/node-app/update-check-web-7001/node_modules/.0.9.0@egg
","baseDir":"/home/node-app/update-check-web-7001","port":7001,"workers":1,"plugins":null,"https":false,"key":"","cert":"","clusterPort":33900}"]
2017-02-23 22:01:37,045 INFO 24714 [egg:logger] init all loggers with
options:
{"dir":"/root/logs/egg-mhsq-app","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-mhsq-app-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"agent"}
2017-02-23 22:01:37,145 WARN 24714 [egg-watcher] defaultEventSource
watcher will NOT take effect
2017-02-23 22:01:37,148 INFO 24714 [egg:agent] create an AgentWorkerClient
for "watcher"
2017-02-23 22:01:37,557 INFO 24714 [egg-mongoose] connecting mongodb://
172.16.0.90:27017/update-check
2017-02-23 22:01:37,763 INFO 24714 [egg-mongoose] starting...
2017-02-23 22:01:37,768 INFO 24714 [egg:watcher:agent] watcher start
success
(node:24714) DeprecationWarning: Mongoose: mpromise (mongoose's default
promise library) is deprecated, plug in your own promise library instead:
http://mongoosejs.com/docs/promises.html
2017-02-23 22:01:37,808 INFO 24714 [egg-mongoose] mongodb://
172.16.0.90:27017/update-check connected successfully
2017-02-23 22:01:37,845 INFO 24714 [egg-mongoose] start successfully and
server status is ok
2017-02-23 22:01:37,862 INFO 24708 [master] Agent Worker started (1338ms)
2017-02-23 22:01:37,873 INFO 24708 [master] App Worker#1:24724 start,
state: none, current workers: ["1"]
2017-02-23 22:01:38,691 INFO 24724 [egg:logger] init all loggers with
options:
{"dir":"/root/logs/egg-mhsq-app","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-mhsq-app-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-02-23 22:01:38,695 INFO 24724 [egg:worker] create an AppWorkerClient
for "watcher"
2017-02-23 22:01:38,749 INFO 24724 [egg-schedule]: register schedule
egg-schedule:/home/node-app/update-check-web-7001/node_modules/.2.2.2@egg-logrotator
/app/schedule/clean_log.js
2017-02-23 22:01:38,749 INFO 24724 [egg-schedule]: register schedule
egg-schedule:/home/node-app/update-check-web-7001/node_modules/.2.2.2@egg-logrotator
/app/schedule/rotate_by_file.js
2017-02-23 22:01:39,106 INFO 24724 [egg-mongoose] connecting mongodb://
172.16.0.90:27017/update-check
2017-02-23 22:01:39,382 INFO 24724 [egg-static] starting static serve
/public/ -> /home/node-app/update-check-web-7001/app/public
2017-02-23 22:01:39,389 INFO 24724 [egg-security] use csrf middleware
2017-02-23 22:01:39,390 INFO 24724 [egg-security] use methodnoallow
middleware
2017-02-23 22:01:39,391 INFO 24724 [egg-security] use noopen middleware
2017-02-23 22:01:39,391 INFO 24724 [egg-security] use nosniff middleware
2017-02-23 22:01:39,392 INFO 24724 [egg-security] use xssProtection
middleware
2017-02-23 22:01:39,393 INFO 24724 [egg-security] use xframe middleware
2017-02-23 22:01:39,393 INFO 24724 [egg-security] compose 6 middlewares
into one security middleware
2017-02-23 22:01:39,484 INFO 24724 [egg-mongoose] starting...
(node:24724) DeprecationWarning: Mongoose: mpromise (mongoose's default
promise library) is deprecated, plug in your own promise library instead:
http://mongoosejs.com/docs/promises.html
2017-02-23 22:01:39,528 INFO 24724 [egg-mongoose] mongodb://
172.16.0.90:27017/update-check connected successfully
2017-02-23 22:01:39,580 INFO 24724 [egg-mongoose] start successfully and
server status is ok
2017-02-23 22:01:39,595 WARN 24708 [master] App Worker#1:24724 started at
7001, remain 0 (1733ms)
2017-02-23 22:01:39,595 INFO 24708 [master] egg started on
http://127.0.0.1:7001 (3076ms)


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/eggjs/egg/issues/440, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWA1Qf0FWMtPwiVkj5YmxqgPU7qV1f6ks5rfZOjgaJpZM4MKAge
.

这是处理响应错误了,看看终端有没有打印出来哪里报错了,或者去看错误日志文件,在 logs/${appname}/common-error.log 文件里面

感谢你能如何快速的回复我的问题, 我通过你给出的提示查看了 logs/${appname}/common-error.log 文件, 里面没有任何日志, 通过浏览器访问页面, 终端也没有任何日志产生.

请问生产环境的启动是否还有其他注意事项, 注: 开发模式启动是正常的.

项目中, 我新建了一个 lib/plugin/egg-kue 的插件, 并未以正式插件的形式发布, 而是直接引用的, 这对生产环境的启动是否有影响.

目录文件下有什么其他日志?应该与插件没有关系

我看过日志了, 都是正常的。

确定你找到了 common-error 那个错误文件?会输出这一行的话一定会打印一条错误日志

https://github.com/eggjs/egg-onerror/blob/master/app.js#L62

如果你有时间, 我可以QQ: 168189878 沟通, 谢谢。

你可以找到你 node_modules 里面的 egg/node_modules/egg-onerror 这个插件,在这里 console 打印出来。

issue 沟通,不上 qq

/root/logs/egg-mhsq-app 日志目录在

问题原因找到了.
egg-onerror >>>
{ Error: Please set config.keys first
at Application.get keys [as keys] (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\app\extend\application.js
:114:17)
at Object.get cookies [as cookies] (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\app\extend\context.js:21
:49)
at Object.get [egg-security#CSRF_SECRET] (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\egg-s
ecurity\app\extend\context.js:65:32)
at Object.ensureCsrfSecret (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\egg-security\app\ex
tend\context.js:76:13)
at Object.csrf (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\egg-security\lib\middlewares\cs
rf.js:9:10)
at next (native)
at Object. (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\egg-security\node_module
s\koa-compose\index.js:28:19)
at next (native)
at onFulfilled (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:65:19)
at F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:54:5
at Object.co (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:50:10)
at Object.toPromise (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:118:63)
at next (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:99:29)
at onFulfilled (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:69:7)
at F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:54:5
at Object.co (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:50:10)
at Object.toPromise (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:118:63)
at next (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:99:29)
at onFulfilled (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:69:7)
at F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:54:5
at Object.co (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:50:10)
at Object.toPromise (F:\dev\nodejs\egg\egg-mhsq-app\node_modules\egg\node_modules\co\index.js:118:63) status
: 500 }

请教如何配置. 这个是我本地环境.

在 config.default.js 里面加入配置项:

exports.keys = 'your secret key';

里面填你的秘钥,这个在开发环境执行就有提示的,你一直没配。。

@hsxiaoma 错误日志找不到的原因是:生产环境下 logger 会将日志默认打印到 $HOME/logs/${appname} 下面,而不是之前的应用根目录下

之前也遇到一样的问题, @hsxiaoma , 后来看日志发现 在prod 环境下需要配置 config.keys.
@dead-horse 的解决办法是非常有效的。
我觉得这个应该在官网上稍微重点的提示出来。

@fengmk2 @popomore 直接在开发环境就抛错吧,设置成必选项好了,现在开发环境的提示没人会看

感谢协助解决问题, 同 liyanlong 建议一样, 要在文档里强调一下, 并作为强制项.

必选项,或在 egg-security 里面启动时做检查,打印到日志 warning

发自我的 iPhone

在 2017年2月23日,23:11,天马行空 notifications@github.com 写道:

感谢协助解决问题, 同 liyanlong 建议一样, 要在文档里强调一下, 并作为强制项.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

有 warn 的,改必选吧,不过用例得改了
TZ | 天猪 notifications@github.com于2017年2月23日 周四23:32写道:

必选项,或在 egg-security 里面启动时做检查,打印到日志 warning

发自我的 iPhone

在 2017年2月23日,23:11,天马行空 notifications@github.com 写道:

感谢协助解决问题, 同 liyanlong 建议一样, 要在文档里强调一下, 并作为强制项.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/eggjs/egg/issues/440#issuecomment-282024855, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAWA1dShTwjERpgpKQg8bin2wPvp4b0aks5rfaZ3gaJpZM4MKAge
.

@liyanlong 请问密钥是哪里生成的呢

config.default.js 里面的 key,自己输入一个随机字符串

@atian25 config.keys = '_1504579949993_3692'; 任然报这个错误
这是config.default.js的配置

config.keys = '_1504579949993_3692';
  config.key = appInfo.name + '_1504579949993_3692';
  config.security = {
    csrf: false,
    debug: 'csrf-disable',
    domainWhiteList: [ 'http://localhost:8080' ],
  };
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };

提供完整的配置

'use strict';

const path = require('path');
module.exports = appInfo => {
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = '_1504579949993_3692';
  config.key = appInfo.name + '_1504579949993_3692';
  config.security = {
    csrf: false,
    debug: 'csrf-disable',
    domainWhiteList: [ 'http://localhost:8080' ],
  };
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };

  return config;
};

为什么有 config.keysconfig.key

这段看不出啥,提供错误日志,还有最小可复现仓库吧

确实看不出来问题,但是后台的错误一直报:Please set config.keys first

单独提 issue 提供可复现 demo,猜测这个文件不是 config.default.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

occultskyrong picture occultskyrong  ·  35Comments

Yao-JSON picture Yao-JSON  ·  34Comments

fengmk2 picture fengmk2  ·  51Comments

popomore picture popomore  ·  53Comments

musicode picture musicode  ·  55Comments