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

news/2024/10/22 21:44:01/

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.ppmy.cn/news/1239319.html

相关文章

Springboot引入分布式搜索引擎Es RestAPI

文章目录 RestAPI初始化RestClient创建索引库删除索引库判断索引库是否存在总结 RestClient操作文档增加文档数据查询文档删除文档修改文档批量导入文档小结 RestAPI ES官方提供了各种不同语言的客户端,用来操作ES。这些客户端的本质就是组装DSL语句,通…

C++ 指针进阶:动态分配内存

工作原理 malloc 是 stdlib.h 库中的函数,声明为 void *__cdecl malloc(size_t _Size); 原理: malloc 函数沿空闲链表(位于内存 堆空间 中)申请一块满足需求的内存块,将所需大小的内存块分配给用户剩下的返回到链表上; 并返回指向该内存区的首地址的指针,意该指针的类型…

c# 逆变 / 协变

个人理解: 1. 逆变in向上兼容类 2. 协变out向下兼容类 在面向对象编程中,尤其是使用泛型时,in和out关键字用于限制类型参数的协变性和逆变性。 in关键字(逆变): in关键字用于标记泛型类型参数的逆变性。…

VL06O报表添加增强字段

业务描述 用户需要在VL06O事务代码下进行批量交货过账,现有的筛选条件不太适用当前公司的业务,需要在报表中新增三个交货单增强字段,方便其筛选(选择屏幕没有加,用户在报表里用标准按钮功能自己筛选) 效果…

Azure Machine Learning - Azure可视化图像分类操作实战

目录 一、数据准备二、创建自定义视觉资源三、创建新项目四、选择训练图像五、上传和标记图像六、训练分类器七、评估分类器概率阈值 八、管理训练迭代 在本文中,你将了解如何使用Azure可视化页面创建图像分类模型。 生成模型后,可以使用新图像测试该模型…

python命令行交互 引导用户选择宠物

字多不看,直接体验 代码 以下代码将在命令行中,引导用户选择一个或者多个宠物,并反馈用户选择的宠物 # -*- coding:UTF-8 -*- """ author: dyy contact: douyaoyuan126.com time: 2023/11/22 15:19 file: 在命令行中引导用户…

如何用SWIG封装c++接口给java使用?

SWIG是什么? SWIG(Simplified Wrapper and Interface Generator)是一个将C/C接口转换为其他语言接口的工具,从而可以讲C/C的库集成到其他语言的系统中。目前SWIG已经可以支持Python, Java, C#,Ruby,PHP,R语言等十多种语言。 官方网址&…

Dreamview底层实现原理

1. Dreamview底层实现原理(3个模块) (1) HMI--可视化人机交互 a. HMIConfig: 1) 支持哪些模式;2)支持哪些地图;3)支持哪些车辆;4)HMIAction HMIMode: b.HMIStatus (2) SimControl (3) Monitor--监视自动驾驶行驶过程中软硬件状态 Referenc…