SSM聚合项目+Vue3+Element-plus项目生产部署(Ubuntu24.04LTS)

embedded/2025/2/8 8:56:24/

非常刺激的一次部署经历,我相信很多第一次独立部署前后端分离项目的人都遇到过

后端部署

jdk环境

安装jdk,解压后配置环境变量即可

tomcat运行war包

需要在tomcat的conf/sever.xml中配置SSM聚合项目的每一个子项目的服务(标签),这样tomcat运行的时候就会自动启动对应的服务

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener" /><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /><GlobalNamingResources><Resource name="UserDatabase" auth="Container"type="org.apache.catalina.UserDatabase"description="User database that can be updated and saved"factory="org.apache.catalina.users.MemoryUserDatabaseFactory"pathname="conf/tomcat-users.xml" /></GlobalNamingResources><Service name="Catalina"><Connector port="8088" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" /><Engine name="Catalina" defaultHost="localhost"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost"  appBase="webapps"unpackWARs="true" autoDeploy="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".txt"pattern="%h %l %u %t &quot;%r&quot; %s %b" /></Host></Engine></Service>
<Service name="Catalina1"><!-- 每个项目的端口号也要进行区分,保证不被占用 --><Connector port="9090" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" URLEncoding="UTF-8"/><Connector port="8010" protocol="AJP/1.3" redirectPort="8443" secretRequired=""/><Engine name="Catalina1" defaultHost="localhost"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost"  appBase="webapps"unpackWARs="true" autoDeploy="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".txt"pattern="%h %l %u %t &quot;%r&quot; %s %b" /><!-- 这里是想要部署的对应项目的名称 --><Context docBase="cinema_portal-1.0-SNAPSHOT" path="/" reloadable="true"/></Host></Engine></Service><Service name="Catalina2"><Connector port="9091" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" URLEncoding="UTF-8"/><Connector port="8011" protocol="AJP/1.3" redirectPort="8443" secretRequired=""/><Engine name="Catalina2" defaultHost="localhost"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm"resourceName="UserDatabase"/></Realm><Host name="localhost"  appBase="webapps"unpackWARs="true" autoDeploy="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"prefix="localhost_access_log" suffix=".txt"pattern="%h %l %u %t &quot;%r&quot; %s %b" /><Context docBase="cinema_console-1.0-SNAPSHOT" path="/" reloadable="true"/></Host></Engine></Service>
</Server>

前端部署

前端打包+前端部署

前端vue项目打包之后,会产生一个dist文件夹,里面是该项目的静态运行文件

解压到一个指定的路径

使用nginx反向代理这个路径,使我们可以直接访问到这个路径

user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;events {worker_connections 768;# multi_accept on;
}http {### Basic Settings##sendfile on;tcp_nopush on;types_hash_max_size 2048;# server_tokens off;# server_names_hash_bucket_size 64;# server_name_in_redirect off;include /etc/nginx/mime.types;default_type application/octet-stream;### SSL Settings##ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLEssl_prefer_server_ciphers on;### Logging Settings##access_log /var/log/nginx/access.log;### Gzip Settings##gzip on;# gzip_vary on;# gzip_proxied any;# gzip_comp_level 6;# gzip_buffers 16 8k;# gzip_http_version 1.1;# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;### Virtual Host Configs##include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*;
}#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

然后在/etc/nginx/sites-enabled下,我们可以发现这样一个配置文件:

server {listen 8080;  # 监听端口,处理HTTP请求server_name ;  # 处理的域名(如果没有域名就写公网IP)root /usr/zxk/project/front/dist;  # 网站根目录,Nginx将从这里提供文件(就是你的dist文件夹目录)index index.html;  # 默认首页文件location / {try_files $uri $uri/ /index.html;add_header Cache-Control no-cache;}location = /index.html {add_header Cache-Control no-cache;}location ~ .(css|js|jpg|jpeg|png|gif|ico|svg)$ {expires 30d;  # 设置静态资源的缓存时间为30天add_header Cache-Control "public";  # 添加缓存控制头root /usr/zxk/project/front/dist;}error_page 404 /404.html;  # 自定义404错误页面location = /404.html {internal;  # 仅内部请求可以访问404页面}location ~ /.ht {deny all;  # 禁止访问以.开头的文件(如.htaccess)}
}

可以看到我们映射了8080端口,使其访问/usr/zxk/project/front/dist文件夹的内容


http://www.ppmy.cn/embedded/160503.html

相关文章

C语言的物联网

C语言在物联网中的应用 物联网&#xff08;Internet of Things&#xff0c;IoT&#xff09;是一个通过网络将各种物理设备连接起来的系统&#xff0c;使其能够收集和交换数据。随着技术的进步&#xff0c;物联网已经走入了我们的日常生活&#xff0c;并在智能家居、智能城市、…

C++ Primer 递增和递减运算符

欢迎阅读我的 【CPrimer】专栏 专栏简介&#xff1a;本专栏主要面向C初学者&#xff0c;解释C的一些基本概念和基础语言特性&#xff0c;涉及C标准库的用法&#xff0c;面向对象特性&#xff0c;泛型特性高级用法。通过使用标准库中定义的抽象设施&#xff0c;使你更加适应高级…

vite共享配置之---css相关

vite和webpack都有对样式的处理&#xff0c;涉及到的有css、sass、scss、postcss、模块化&#xff0c;以下是vite和webpack对样式的处理方式 特性ViteWebpackCSS 处理方式自动处理&#xff0c;无需配置&#xff0c;使用浏览器的原生支持需要配置 style-loader 和 css-loader&a…

110,【2】攻防世界 web mfw

进入靶场看到git想到git泄漏 &#xff0c;试试 .git 能访问到&#xff0c;确实存在&#xff0c;需要使用工具了 有两个 githack和githacker githack 指的是一款用于利用 Git 仓库泄露漏洞来恢复完整源代码的工具 使用下面这两个命令在Kali安装 git clone https://github.c…

【慕伏白教程】Zerotier 连接与简单配置

文章目录 下载与安装 WindowsLinux apt安装官方脚本安装 Zerotier 配置 新建网络网络配置 终端配置 WindowsLinux 下载与安装 Windows 进入Zerotier官方下载网站&#xff0c;点击下载 在下载目录找到安装文件&#xff0c;双击打开后点击 Install 开始安装 安装完成后&…

2025年叉车司机考试真题及答案

叉车考证的必要性主要体现在以下几个方面&#xff1a; 1、法律法规要求 &#xff1a; 根据《国家特种设备安全监察条例》和《安全生产法》等相关法律规定&#xff0c;从事特种设备作业的人员必须通过培训和考试&#xff0c;获得国家统一格式的特种作业证书后&#xff0c;才能…

WPF 在后台使TextBox失去焦点的方法

在软件设计开发的时候&#xff0c;偶尔会遇到在后台xaml.cs后台中&#xff0c;要将TextBox控件的焦点取消或者使TextBox控件获取焦点&#xff0c;下面介绍讲述一种简单的“只让特定的 TextBox 失去焦点”方法: 前端xaml代码示例&#xff1a; <StackPanel Orientation"…

51单片机看门狗系统

在 STC89C52 单片机中&#xff0c;看门狗控制寄存器的固定地址为 0xE1。此地址由芯片厂商在硬件设计时确定&#xff0c;但是它在头文件中并未给出&#xff0c;因此在使用看门狗系统时需要声明下这个特殊功能寄存器 sfr WDT_CONTR 0xE1; 本案将用一个小灯的工作状况来展示看门…