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

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 + 端口 访问前端项目。
注:端口需要在服务器防火墙开启对外开放。

http://www.lryc.cn/news/247858.html

相关文章:

  • Egg.js中Cookie和Session
  • 与 PCIe 相比,CXL为何低延迟高带宽?
  • Vue 入门指南:从零开始学习 Vue 的基础知识
  • 11.docker的网络-docker0的理解及bridge网桥模式的介绍与实例
  • 新材料制造ERP用哪个好?企业应当如何挑选适用的
  • vr小鼠虚拟解剖实验教学平台减少了受感染风险
  • 【算法萌新闯力扣】:环形链表及环形链表II
  • 10.docker的网络network-概述
  • CodeTON Round #7 (Div. 1 + Div. 2)
  • 剑指 Offer(第2版)面试题 10:斐波那契数列
  • Debian 12 / Ubuntu 22.04 安装 Docker 以及 Docker Compose 教程
  • Spark_spark参数配置优先级
  • ElasticSearch之Search settings
  • 二十二、数组(4)
  • 『 MySQL数据库 』CRUD之UD,表的数据更新(修改)及删除
  • 贪心算法及相关例题
  • 给企业做公众号运营你都有哪些宝贵经验?
  • 2023亚太地区数学建模B题思路分析+模型+代码+论文
  • Electron+Ts+Vue+Vite桌面应用系列:sqlite增删改查操作篇
  • c语言编程题经典100例——(36~40例)
  • SQL Server实现参数化增删改查Class类
  • 【Linux】 sudo命令使用
  • Redis key的类型以及命令
  • 数组元素积的符号
  • 数据脱敏方案
  • 蓝桥杯每日一题2023.11.28
  • 【数据库连接池】01:连接池初始化
  • Java基于springboot开发的土特产网站商城多商家源码
  • Linux CentOS7 LVM
  • ArkTS开发webview,html页面中的input和按钮等操作均无响应 【Bug已解决-鸿蒙开发】