本文环境 Centos7, apache http 2.4
nodejs 的 forever 命令很实用,使nodejs 程序持久运行,使用中遇到的几个步骤,记录于此:
1,如何安装
yum inistall -y nodejs npm
npm update
npm install -g forever
npm 是 JavaScript 世界的包管理工具,并且是 Node.js 平台的默认包管理工具。
2,常见使用
forever start server.js #启动应用
forever stop server.js #关闭应用
forever restartall #重启所有应用
forever stopall #停止所有应用
forever logs #列出日志存放目录
配置 apache httpd 2.4 反向代理,可支持 websocket ,
配置之前,需要确认httpd已经加载 ,运行:
apachectl -t -D DUMP_MODULES
应包含如下等模块:
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_http_module (shared)
proxy_wstunnel_module (shared)
修改 httpd 配置文件 /etc/httpd/conf/httpd.conf,添加如下内容:
<VirtualHost *:80>
ServerAdmin support@innovatedata.com
ServerName www.innovatedata.com
ErrorLog logs/xmrminer-error_log
CustomLog logs/xmrminer-access_log common
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:7777/
ProxyPassReverse / http://127.0.0.1:7777/
ProxyRequests Off
RewriteEngine On
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://localhost:7777/$1 [P]
</VirtualHost>