Linux云服务器打包部署前端Vue项目

1. 打包

在项目包的终端使用命令打包成dist文件。

npm run build

2. Linux云服务器上创建文件夹

mkdir /home/www/dist

注:dist文件夹不用创建,将打包好的dist.zip放进去,然后解压就行。

3. 安装nginx

yum install -y nginx

4. 修改配置文件

vim /etc/nginx/nginx.conf

配置文件原样:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}
http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
    # Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

我们可以看到其中一行

 include /etc/nginx/conf.d/*.conf;

说明他包含同级conf.d目录下的*.conf文件;所以根据个人喜好,我进入conf.d目录,创建xxx.conf文件,配置如下:

    server {
        listen       9999;
        server_name  _;
        root         /home/vue/dist;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }

        location /{
            root /home/vue/dist;
            index index.html;
            try_files $uri $uri/ /index.html;
        } 
    }    

被一个点卡了很久:!!!这个是用来解决刷新路由404问题,写全,可能因为版本问题,不写全导致一直说配置格式错误啥的…可累死我了!!!

        location / {
            root /home/vue/dist;
            index index.html;
            try_files $uri $uri/ /index.html;
        }  

5. 启动 / 重启 nginx

启动:

nginx

重启:

nginx -s reload

6. 访问前端项目

使用服务器 IP + 端口 访问前端项目。
注:端口需要在服务器防火墙开启对外开放。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Linux系统上打包部署springboot+vue项目的步骤如下: 1. 首先,你需要拉取git仓库的代码。复制git仓库的地址,并在Linux系统中使用命令拉取代码。\[1\] 2. 接下来,你需要打包Java项目。进入项目的目录,执行打包命令,生成一个jar包。你可以使用命令`java -jar springboot-affair-0.0.1-SNAPSHOT.jar`来运行打包好的Java项目。\[3\] 3. 然后,你需要部署前端vue项目。同样进入项目的目录,执行打包命令,生成前端的静态文件。将生成的静态文件部署到Nginx服务器上。 4. 在部署之前,确保Nginx、MySQL、Redis和MinIO已经启动。你可以使用相应的命令来启动这些服务。 5. 最后,访问你的项目。通过浏览器访问Nginx服务器的地址,即可查看部署好的springboot+vue项目。 总结起来,你需要拉取代码,打包Java项目部署前端项目,启动Nginx、MySQL、Redis和MinIO,然后访问项目即可。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [Linux——在Linux系统上打包部署springboot+vue项目,nginx+mysql+redis+minio](https://blog.csdn.net/weixin_56039103/article/details/126173205)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [使用docker部署springboot+vue项目](https://blog.csdn.net/Ruhoney908/article/details/131024801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木木是木木

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值