[英]pm2 app in symlink'd directory yields 502 Bad Gateway
I have a node.js application configured to run via pm2
in a directory structure like this: 我有一个配置为通过
pm2
在目录结构中运行的node.js应用程序,如下所示:
/opt/project/v1/web/index.js
/opt/project/current -> /opt/project/v1
That is, current is a symlink to v1 . 也就是说, current是到v1的符号链接。 I need
pm2
to start the app in current/web , not in v1/web . 我需要
pm2
在current / web中启动应用程序,而不是在v1 / web中启动 。
I first did this: 我首先这样做:
cd /opt/project/current/web
pm2 start index.js
The web site ran fine, but pm2
resolved the symlink to /opt/project/v1/web/index.js . 该网站运行正常,但
pm2
解决符号链接到/opt/project/v1/web/index.js。 So I found this forum thread about pm2
resolving symlinks , and from there I tried this instead: 因此,我找到了这个有关
pm2
解决符号链接的论坛主题 ,然后从那里尝试了这一点:
cd /opt/project
pm2 start current/web/index.js
The process appeared to start, and pm2
showed it in the list and showed the symbolic path, except visiting the page now yields a 502 (Bad Gateway) error. 该过程似乎开始了,
pm2
在列表中显示了它并显示了符号路径,但现在访问该页面会产生502(错误网关)错误。
The output of pm2 show
for that last attempt is: 上一次尝试的
pm2 show
的输出是:
┌───────────────────┬───────────────────────────────────────┐
│ status │ online │
│ name │ index │
│ restarts │ 7 │
│ uptime │ 2s │
│ script path │ /opt/project/current/web/index.js │
│ script args │ N/A │
│ error log path │ /root/.pm2/logs/index-error-0.log │
│ out log path │ /root/.pm2/logs/index-out-0.log │
│ pid path │ /root/.pm2/pids/index-0.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 0 │
│ exec cwd │ /opt/project │
│ exec mode │ fork_mode │
│ node.js version │ 6.8.1 │
│ watch & reload │ ✘ │
│ unstable restarts │ 0 │
│ created at │ 2016-12-03T22:08:58.972Z │
└───────────────────┴───────────────────────────────────────┘
Thinking that perhaps the different cwd was a problem, I then tried this, also from that thread: 考虑到也许其他的cwd可能是一个问题,然后我从那个线程尝试了这个:
Create a file app.json : 创建一个文件app.json :
{ "apps": [ { "name": "index", "script": "index.js", "args": [], "watch": true, "node_args": "", "merge_logs": true, "cwd": "/opt/project/current/web", "env": { } } ] }
Start with pm2 start app.json
pm2 start app.json
When I did it this way the results were the same as the previous attempt except pm2
showed the correct cwd, but still got a 502. 当我这样做时,结果与之前的尝试相同,只是
pm2
显示正确的cwd,但仍然得到502。
None of the log files seem to show any errors and pm2 shows the app as online. 日志文件似乎都未显示任何错误,pm2显示该应用程序为在线。
I really don't know anything about node.js or pm2
, I was handed an existing system and tasked with reorganizing the file system a bit. 我真的对node.js或
pm2
一无所知,我被交给了一个现有的系统,并承担了重新组织文件系统的任务。 I have a very basic working knowledge of pm2
's commands now, but that's about it. 现在,我对
pm2
的命令有了非常基本的工作知识,但是仅此而已。
So my question is: How can I get the app to run in the symlink'd path and why does it respond with a 502 when I try? 所以我的问题是:如何使该应用程序在symlink的路径中运行,为什么在尝试时它以502响应?
Well, I figured it out. 好吧,我知道了。 I solved it by using this configuration file (saved as app.json):
我通过使用以下配置文件(保存为app.json)解决了该问题:
{
"apps": [
{
"name": "index",
"script": "./index.js",
"cwd": "/opt/project/current/web",
"exec_mode": "fork_mode",
"env": {
}
}
]
}
And starting it like: 像这样开始:
cd /opt/project
pm2 start current/web/app.json
And it worked like a charm, although I'm not sure exactly which difference here solved the problem, I didn't take the time to investigate further. 而且它的工作原理很吸引人,尽管我不确定究竟是哪种差异解决了问题,但我没有花时间进行进一步的研究。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.