当前位置: 首页 > news >正文

linux打包前端vue,后端springboot项目

第一步先对整个项目进行通过maven进行clean在进行compile

第二步直接进行打包package和install都可以

第三部把对应的jar放到服务器上

把jar包放到服务器上某个地址下,然后cd到这个目录下,然后执行命令

nohup java -jar ruoyi-admin.jar > springboot.log 2>&1 &

ps -ef|grep java 可以查看某个进程

第四步打包前端代码

npm run build:prod

打包成功会生成dis

解压放到linux某个目录下/usr/vue

然后进行解压

unzip dist.zip

第五步配置nginx

cd   /usr/local/nginx/conf

找到nginx.conf里面的配置文件应该是这样的

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

直接扔掉

#根据你服务器的cpu核数来确定此值
#user root;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#events事件主要用来确定Nginx使用哪种算法
events {
    worker_connections  2048;
}

http {
    #隐藏Nginx版本信息
    server_tokens off;
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    #代理的相关参数设置 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;

    #启用gzip压缩,提高用户访问速度
     # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

    server_names_hash_bucket_size 128;
    client_max_body_size 100m; 
    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;
        
    #自定义变量 $connection_upgrade
    map $http_upgrade $connection_upgrade { 
        default          keep-alive;  #默认为keep-alive 可以支持 一般http请求
        'websocket'      upgrade;     #如果为websocket 则为 upgrade 可升级的。
    }

    #增加虚拟主机
    include /usr/local/nginx/conf/admin/*.conf;
}

最后一行代码:一定要看这种情况是配置很多的conf然后统一进行转发

# admin
server{
    listen 80;
    server_name localhost;
    location / {
        root   /usr/vue/dist;
        try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }
    location /prod-api/{
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8080/;
        proxy_http_version 1.1;
        proxy_read_timeout 3600s;

        proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
        proxy_set_header Connection $connection_upgrade;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

root  这个是前端刚刚的dist地址

prod-api 这个是前端请求带的前缀

proxy_pass http://127.0.0.1:8080/; 后端地址

配置好了之后重启nginx就可以了

cd /usr/local/nginx/sbin

里面有一个nginx

./nginx -s reload

一定要注册关闭80防火墙,开发80端口,nginx里面的配置是80

ok了

相关文章:

  • CentOS 7 挂载与卸载文件系统笔记
  • 物联网中的物模型是什么意思,在嵌入式软件开发中如何体现?
  • 树——构造和遍历问题——面试专题
  • 屏幕后处理Post-Processing安装及使用
  • 如何学习并使用C++
  • Linux中的信号
  • Table ‘spzx-system.QRTZ_LOCKS‘ doesn‘t exist
  • 安全+低碳+高效:Acrel-3000助力企业打造未来型电能管理体系-安科瑞黄安南
  • 国内AI与国际AI的差距分析
  • 介绍FRAMES:一个统一的检索增强生成评估框架
  • Python入门学习笔记 - 从环境搭建到基础语法
  • 【Java SE】包装类 Byte、Short、Integer、Long、Character、Float、Double、Boolean
  • JDBC删除与查询
  • PLC协议
  • 动态代理模式实现与对比(JDK、CGLIB、Spring AOP)
  • vue数据两个相同的参数对比只显示一个
  • HarmonyOS主题管理工具封装:动态切换、持久化存储与常见问题解析
  • sourcetree中的“master“,“origin/master“,“origin/HEAD“这三个图标都是什么意思?GIT 超详细➕通俗易懂版本
  • Unity中对象池(Object Pool)技术解析与实现
  • 【聚合函数、分组、排序笔记】
  • 泽连斯基:乌克兰已做好与俄罗斯举行会谈的准备
  • 为发期刊,高校学者偷贩涉密敏感数据!国安部披露间谍案细节
  • 新华时评:中国维护国际经贸秩序的立场坚定不移
  • 雷军:过去一个多月是创办小米以来最艰难的时间
  • 5天完成1000多万元交易额,“一张手机膜”畅销海内外的启示
  • 47本笔记、2341场讲座,一位普通上海老人的阅读史