关于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需配置防火墙以及开放端口等操作)

相关推荐
诚信爱国敬业友善5 分钟前
GUI编程(window系统→Linux系统)
linux·python·gui
sekaii6 分钟前
ReDistribution plan细节
linux·服务器·数据库
YH_DevJourney1 小时前
Linux-C/C++《C/8、系统信息与系统资源》
linux·c语言·c++
一小路一1 小时前
Go Web 开发基础:从入门到实战
服务器·前端·后端·面试·golang
威哥爱编程1 小时前
Linux驱动开发13个实用案例
linux
去看日出2 小时前
Linux(centos)系统安装部署MySQL8.0数据库(GLIBC版本)
linux·数据库·centos
qq_448941082 小时前
10、k8s对外服务之ingress
linux·容器·kubernetes
D-river2 小时前
【如何基于Debian构建Kali Linux】
linux·网络·安全·网络安全
小金的学习笔记3 小时前
如何在本地和服务器新建Redis用户和密码
服务器·数据库·redis
年轮不改3 小时前
ARM-Linux 基础项目篇——简单的视频监控
linux·arm开发