ubuntu

  1. apt-get install nginx
    存放配置文件 /etc/nginx

  2. nginx重新加载
    nginx -s reload

  3. 查看使用的端口
    netstat -apn | grep :80, ps -ef | grep nginx
    kill -9 4183

  4. 卸载nginx
    sudo apt-get purge nginx nginx-common # 卸载所有东东,包括删除配置文件

  5. pm2
    npm install pm2 -g
    pm2 status //是否有表格输出
    普通启动(fork模式,无法处理并发)
    pm2 start app.js

重启某个项目pm2 restart 0
pm2 restart 项目Id
重启所有项目
pm2 restart all
pm2 stop 0 停止指定的进程
pm2 delete 0 杀死指定的进程

集群启动(cluster模式,可处理并发)
pm2 start app.js -i 0
查看pm2中的项目运行状态

pm2 l
pm2 list
pm2 status
  1. nodejs配置https, 注意免费的ssl证书1年有效
let express = require("express");
let http = require("http");
let https = require("https");
let fs = require("fs");
// Configuare https
const httpsOption = {
    key : fs.readFileSync("./https/xxxxxxxxxxxx.key"),
    cert: fs.readFileSync("./https/xxxxxxxxxxxx.pem")
}
// Create service
let app = express();
app.get('/', function (req, res) {
  res.send('Hello World! https!');
});
http.createServer(app).listen(80);
https.createServer(httpsOption, app).listen(443);

Nodejs配置Https服务1
Nodejs配置Https服务1

你可能感兴趣的:(ubuntu)