关于node全栈项目打包发布linux项目问题总集

1.用pm2部署nest

说明:如果一开始将nest直接打包放到linux服务器上用pm2执行则会报错,这是因为tsconfig.build.tsbuildinfo文件的路径以及相关依赖问题。

报错会为:什么东西找不到....

所以建议以下为步骤一步一步配置

  1. 将整个nest添加压缩包直接传到的root中的任何一个目录中,在linux中解压
  2. 进入nest的项目文件用npm run build进行打包
  3. 此时需要下载好pm2进程管理器
  4. 直接pm2 start main.js运行后端项目
  5. 此时为了验证后端项目是否正常启动成功 可以在win上的浏览器缩编输入一个后端的get接口来验证

2.安装nginx

因为某些linux服务器为了兼容一些特定的项目使用的老的版本的linux系统,比如我此时用的就是centOS7,因为centOS7在2024年的6月份就把此linux版本的yum源镜像归档了,所以会导致我们在使用yum源来下载一些工具的时候会出现yum报错的现象。此时别慌,可以按照以下步骤操作!

报错信息如:

Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7\&arch=x86_64\&repo=os\&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"

解决方法

  • 进入/etc/yum.repos.d目录下找到 CentOS-Base.repo
  • cd /etc/yum.repos.d

阿里云镜像源

以下两个命令都可以,执行完成后进入/etc/yum.repos.d

然后执行:

  • cat CentOS-Base.repo

解析nginx

  • yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
  • 此时来到你安装nginx的目录
  • ./configure --prefix=/usr/local/nginx --with-http_ssl_module
  • make&&make install

此时去/usr/local/nginx目录中去找配置好的nginx(此时就可以看到nginx执行文件了)

配置nginx.conf文件

(两个,一个为一开始下载的nginx文件,另一个为解析到/usr/local/nginx之后的文件)

复制代码
http {
    include   mime.types;
    default_type  application/octet-stream;
    server {
        listen 443 ssl;
        server_name 自己解析的域名;
        #你解析域名的密钥文件两个(假如你都放在了/etc/Assl目录下)
        ssl_certificate /etc/Assl/XXXXX.pem;
        ssl_certificate_key /etc/Assl/XXXXX.key;

        location / {
            #访问域名就可以看到的前端项目(假如你都放在了/etc/lesaosao_lunxun_ui目录下)
            root  /etc/lesaosao_lunxun_ui/dist_pc;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

        location /api/ {
            #访问后端项目的端口(ip+端口号)
            proxy_pass http://xxx.xx.xx.xx:3000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        location /images/uploadimg/ {
            #访问后端存放前端上传的图片目录
            alias /root/usr/lesaosao_lunxun/uploadimg/;
        }

        # SSL configurations
        proxy_ssl_session_reuse off;
        proxy_ssl_protocols TLSv1.2 TLSv1.3;
        proxy_ssl_ciphers HIGH:!aNULL:!MD5;
    }

    server {
        #第二个前端项目(假如不需要使用域名访问)
        listen 8100;

        location / {
             #访问8100端口就可以看到的前端项目(假如你都放在了/etc/lesaosao_lunxun_ui目录下)
            root /etc/lesaosao_lunxun_ui/dist_web;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

        location /api/ {
            #访问后端项目的端口(ip+端口号)
            proxy_pass http://xxx.xx.xx.xx:3000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        #因为该前端不涉及上传图片等文件所以该目录可忽略
        location /images/uploadimg/ {
            alias /images/uploadimg/;
        }

        # SSL configurations
        proxy_ssl_session_reuse off;
        proxy_ssl_protocols TLSv1.2 TLSv1.3;
        proxy_ssl_ciphers HIGH:!aNULL:!MD5;
    }
}
events {
    	worker_connections  1024;
	}

重启nginx服务!

发现访问域名项目即可被访问到!(特殊linux需配置防火墙以及开放端口等操作)

相关推荐
huangyuchi.19 分钟前
【Linux系统】动静态库的制作
linux·运维·服务器·动态库·静态库·库的简单制作
闻不多21 分钟前
用llamaindex搭建GAR遇到400
android·运维·服务器
jim写博客1 小时前
Linux进程概念(四)环境地址变量
linux·运维·服务器
是小崔啊1 小时前
【Jenkins】01 - Jenkins安装
运维·jenkins
稚辉君.MCA_P8_Java1 小时前
豆包 Java的23种设计模式
java·linux·jvm·设计模式·kubernetes
Nie_Xun2 小时前
ubuntu网络共享
linux·运维·ubuntu
天上掉下来个程小白2 小时前
Docker-14.项目部署-DockerCompose
运维·docker·微服务·容器
花小璇学linux2 小时前
imx6ull-驱动开发篇22——Linux 时间管理和内核定时器
linux·运维·驱动开发
189228048612 小时前
NY270NY273美光固态闪存NY277NY287
服务器·网络·数据库·科技·性能优化
你好,赵志伟4 小时前
Socket 编程 TCP
linux·服务器·tcp/ip