1. 程式人生 > >nodejs 的 forever 和 appache httpd2.4 反向代理的使用和配置

nodejs 的 forever 和 appache httpd2.4 反向代理的使用和配置

本文環境 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 [email protected]
    ServerName xmrminer.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>