[Unit] Description=nodejs server [Service] ExecStart=/usr/bin/node /var/nodejs/index.js Restart=always User=nobody Group=nobody Environment=PATH=/usr/bin:/usr/local/bin Environment=NODE_ENV=production WorkingDirectory=/var/nodejs [Install] WantedBy=multi-user.target |
var http = require('http'); var hostname = '10.10.10.10'; var port = 3849; http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).listen(port, hostname, function () { console.log('Server running at http://%s:%s/', hostname, port); }); |
重新載入所有service
systemctl daemon-reload
啟動 nodejs service
systemctl start nodejs
用lynx連結 http://10.10.10.10:3849,網頁顯示 Hello World 表示成功
設定自動啟動 nodejs
systemctl enable nodejs
沒有留言:
張貼留言