Ubuntu Nodejs 配置

参考这个 blog/Node.js项目线上服务器部署与发布.md at master · savoygu/blog (github.com)

一、配置

  1. nodejs 环境

    安装nvm

    $ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash 
    $ source ~/.bashrc
    
    # 使用nvm安装16
    $ nvm i 16
    $ nvm ls 
    $ nvm use 18.15.0
    $ npm install pm2 -g
    $ pm2 start index.js
    
  2. nginx配置

    # path: /etc/nginx/sites-available/xxx.xx.xxx
    upstream gusaifei {
        server 127.0.0.1:8081;
    }
    server {
        listen 80;
        server_name dysign.czyxcy.com;
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_pass http://gusaifei;
            proxy_redirect off;
        }
    }
    
  3. 直接运行打包的项目

    $ npm install -g serve
    
  1. 一些问题

    node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28’ not found (required by node)

    # 版本号为18的时候会出现问题 16 没事
    $ nvm i 16
    

未经允许不得转载