node.js - Passenger、Plesk 和 Node.js : address already in use

标签 node.js nginx passenger plesk

我的问题是如何让 Phusion Passenger 和 Plesk Onyx 17.5.3 很好地协同工作。我有一台运行 Ubuntu 16.04 的新服务器。

我正在按照官方 Phusion Passenger tutorial 部署 Node.js 应用程序,并且我已经成功地遵循了它,直到我需要 tell Passenger to listen on port 80

这是我的步骤:

  • 我通过注册商为子域 pass.domain.com 设置了一个 DNS 条目
  • 在 Plesk 界面中,我定义了新的子域
  • 如果我在浏览器中访问 http://pass.domain.com,我会看到默认的 Plesk 网页。
  • 我按照“Phusion Passenger:Node.js 教程”进行操作,直到我 reach this command :

sudo乘客启动--端口80--用户一些用户名--环境生产--daemonize

  • 注意:我使用有效的自定义用户名代替“someusername”。
  • 我收到此错误:
Could not start the Nginx engine:  
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)  
nginx: [emerg] still could not bind()

看来 Plesk 已在该地址提供默认网页,因此 Phusion Passenger 无法访问它。我需要添加或编辑哪些文件才能让 Plesk 发布地址以便 Passenger 可以使用它?

编辑 4:我发现 this question 描述了类似的症状。然而,OP 使用的是 Meteor Up,而我使用的是 Passenger。他的解决方案是让 Meteor Up 告诉 Node.js 在端口 3001 上运行,并让 nginx 监听端口 80 并代理对端口 3001 的请求。我了解到 Phusion Passenger 已经在幕后做了类似的事情。

有没有办法修改passenger start命令来澄清这一点?

<小时/>

较旧的编辑

<小时/>

编辑1:响应@TarunLalwali,以下是此服务器上sudo netstat -plnat 的输出:

$ sudo netstat -plnat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:4190            0.0.0.0:*               LISTEN      15234/dovecot   
tcp        0      0 127.0.0.1:12768         0.0.0.0:*               LISTEN      15654/psa-pc-remote
tcp        0      0 0.0.0.0:993             0.0.0.0:*               LISTEN      15234/dovecot   
tcp        0      0 0.0.0.0:995             0.0.0.0:*               LISTEN      15234/dovecot   
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2293/mongod     
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN      15234/dovecot   
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN      15234/dovecot   
tcp        0      0 127.0.0.1:783           0.0.0.0:*               LISTEN      1315/.spamassassin
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26659/nginx     
tcp        0      0 0.0.0.0:8880            0.0.0.0:*               LISTEN      23894/config    
tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      2142/master     
tcp        0      0 172.17.0.1:53           0.0.0.0:*               LISTEN      17312/named     
tcp        0      0 94.76.206.212:53        0.0.0.0:*               LISTEN      17312/named     
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      17312/named     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1413/sshd       
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      12563/passenger-sta
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      17312/named     
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      2142/master     
tcp        0      0 94.76.206.212:443       0.0.0.0:*               LISTEN      26659/nginx     
tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN      23894/config    
tcp        0      0 94.76.206.212:993       92.130.47.95:49994      ESTABLISHED 15322/imap-login
tcp        0      0 127.0.0.1:51168         127.0.0.1:12768         TIME_WAIT   -               
tcp        0      0 94.76.206.212:25        200.188.141.75:51400    TIME_WAIT   -               
tcp        0    188 94.76.206.212:22        92.130.47.95:34414      ESTABLISHED 4035/sshd: blacksla
tcp6       0      0 :::4190                 :::*                    LISTEN      15234/dovecot   
tcp6       0      0 :::993                  :::*                    LISTEN      15234/dovecot   
tcp6       0      0 :::995                  :::*                    LISTEN      15234/dovecot   
tcp6       0      0 :::7080                 :::*                    LISTEN      26432/apache2   
tcp6       0      0 :::7081                 :::*                    LISTEN      26432/apache2   
tcp6       0      0 127.0.0.1:3306          :::*                    LISTEN      10040/mysqld    
tcp6       0      0 :::106                  :::*                    LISTEN      1532/xinetd     
tcp6       0      0 :::110                  :::*                    LISTEN      15234/dovecot   
tcp6       0      0 :::143                  :::*                    LISTEN      15234/dovecot   
tcp6       0      0 ::1:783                 :::*                    LISTEN      1315/.spamassassin
tcp6       0      0 2a02:af8:1:900::3860:80 :::*                    LISTEN      26659/nginx     
tcp6       0      0 :::8880                 :::*                    LISTEN      23894/config    
tcp6       0      0 :::465                  :::*                    LISTEN      2142/master     
tcp6       0      0 :::53                   :::*                    LISTEN      17312/named     
tcp6       0      0 :::21                   :::*                    LISTEN      1532/xinetd     
tcp6       0      0 :::22                   :::*                    LISTEN      1413/sshd       
tcp6       0      0 :::25                   :::*                    LISTEN      2142/master     
tcp6       0      0 2a02:af8:1:900::386:443 :::*                    LISTEN      26659/nginx     
tcp6       0      0 :::8443                 :::*                    LISTEN      23894/config 

注意:我已经在 Plesk forum 上询问过这个问题,但尚未收到回复。我希望在这里询问 Phusion Passenger 社区会更有成效。一旦找到可行的解决方案,我将在此处发布 Plesk 论坛的答案链接。

预先感谢您的见解,

詹姆斯

<小时/>

编辑2:按照@TarunLalwali的建议,我尝试停止nginx,但这产生了一个未知错误:

$ sudo nginx -s stop
$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)
<小时/>

编辑3:在调用 Passenger 之前尝试在服务器范围内禁用 nginx:

$ sudo systemctl disable nginx
Synchronizing state of nginx.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install disable nginx
insserv: warning: current start runlevel(s) (empty) of script `nginx' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `nginx' overrides LSB defaults (0 1 6).

$ systemctl status nginx
* nginx.service - Startup script for nginx service
  Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: enabled)
  Active: inactive (dead)

$ sudo passenger start --port 80 --user node --environment production --daemonize
Could not start the Nginx engine:
nginx: [alert] Unable to start the Phusion Passenger watchdog because it encountered the following error during startup: Unable to start the Passenger core: it seems to have crashed during startup for an unknown reason, with exit code 1 (-1: Unknown error)

最佳答案

您提到您需要系统 Nginx(端口 80)来在服务器上运行其他子域。

Passenger Standalone 可以通过两个步骤与系统 Nginx 和平共存:

  1. 在不冲突的端口上运行它,例如默认的 3000:

    sudo guest start --port 3000 --user someusername --environment production --daemonize

  2. 对于您希望 Passenger 作为服务器的域,请告诉系统 Nginx 代理到 Passenger。

    proxy_pass http://localhost:3000;

记住重新加载/重新启动 Nginx 以激活配置。

如何在 Plesk 中精确执行步骤 2 是 Plesk 论坛上最好提出的问题,但从乘客的角度来看,此设置应该可行。

关于node.js - Passenger、Plesk 和 Node.js : address already in use,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46891011/

相关文章:

angularjs - 在 mean.js 项目中运行 npm test 时出错

security - Nginx 从代理服务器中删除 Cookie 的安全标志

ruby-on-rails - 使用 Apache 2、Rails 3.2 和 Phusion Passenger 配置子 uri 时遇到问题

ruby-on-rails - 将乘客 5.0.23 native 支持与 Ruby 2.2.4 链接失败

ruby-on-rails - 无法加载此类文件 -- mkmf (LoadError)

node.js - NodeJS 需要 ('..' )?

javascript - 在 Async Await 函数中抛出错误后停止执行代码

node.js - 在ElectronJS中检测大写锁定状态

nginx - Kubernetes - 如何在不重启 pod 的情况下动态刷新 secret

nginx - 升级Kubernetes NGINX以在外部指标中使用StackDriver新资源模型