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

React+Springboot项目部署ESC服务器

记录一下我个人部署Linux服务器的心得

环境介绍

ESC服务器创建时默认安装LNMP,即Linux,Nginx,Mysql,Php

所以这里不讲怎么安装Nignx和Mysql

笔者使用的Linux版本为22.0.4LTS版

前端打包

运行React打包命令进行前端项目的打包

npm run build

打包后可能生成dist或者build文件夹,这取决于你构建react项目采用的方式

服务器Nginx的网页目录为/var/www/html文件夹,将上述dist或者build文件夹的内容拷贝到这里

注意:不要将整个文件夹拖入,因为dist或者build文件夹无法识别

服务器Nginx的配置目录为/etc/nginx文件夹,打开nginx.conf文件

 可以看到它包括了下面两个配置

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

我们修改下面那个里面的默认配置文件,同时解决跨域问题

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
### Default server configuration
#
server {listen 80;listen [::]:80;# SSL configuration## listen 443 ssl default_server;# listen [::]:443 ssl default_server;## Note: You should disable gzip for SSL traffic.# See: https://bugs.debian.org/773332## Read up on ssl_ciphers to ensure a secure configuration.# See: https://bugs.debian.org/765782## Self signed certs generated by the ssl-cert package# Don't use them in a production server!## include snippets/snakeoil.conf;root /var/www/html;# Add index.php to the list if you are using PHPindex index.php index.html index.htm index.nginx-debian.html;server_name 39.106.52.24;location /api/ {proxy_pass http://localhost:8081/;  # 后端服务地址proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Scheme  $scheme;      # 传递协议proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Cookie $http_cookie;}location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri $uri/ =404;}# pass PHP scripts to FastCGI server#location ~ \.php$ {include snippets/fastcgi-php.conf;##	# With php-fpm (or other unix sockets):fastcgi_pass unix:/run/php/php8.0-fpm.sock;#	# With php-cgi (or other tcp sockets):#	fastcgi_pass 127.0.0.1:9000;}#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#	deny all;#}
}# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}

后端打包

笔者项目使用gradle创建,所以运行下面命令

gradlew build

接着把build文件夹下的libs中生成的jar文件拷贝到云服务器运行即可

java -jar Sapling-0.0.1-SNAPSHOT.jar

有一种方法可以让jar一直在服务器后台运行。方法就是用下面这行命令运行jar包

nohup java -jar /opt/tracker/Sapling-0.0.1-SNAPSHOT.jar &//注意这里还有& 不要忘记了。

相关文章:

  • 大学之大:东京工业大学2025.5.11
  • Pandas 时间处理利器:to_datetime() 与 Timestamp() 深度解析
  • 17.【.NET 8 实战--孢子记账--从单体到微服务--转向微服务】--微服务基础工具与技术--loki
  • web animation API 锋利的css动画控制器 (更新中)
  • 基于神经网络的无源雷达测向系统仿真实现
  • 深入浅出之STL源码分析2_stl与标准库,编译器的关系
  • 保姆级教程|YOLO11改进】【卷积篇】【4】使用RFAConv感受野注意力卷积,重塑空间特征提取,助力高效提点
  • 《AI大模型应知应会100篇》第58篇:Semantic Kernel:微软的大模型应用框架
  • 【Bootstrap V4系列】学习入门教程之 组件-媒体对象(Media object)
  • Java 原生异步编程与Spring 异步编程 详解
  • 生产级 Flink CDC 应用开发与部署:MySQL 到 Kafka 同步示例
  • C++编程实战--实用代码篇
  • Vue 跨域解决方案及其原理剖析
  • opencascade.js stp vite 调试笔记
  • mac环境配置(homebrew版)
  • JAVA笔记6——异常
  • tokenizer.encode_plus,BERT类模型 和 Sentence-BERT 他们之间的区别与联系
  • spark:map 和 flatMap 的区别(Scala)
  • RDD 两类操作详解(Scala):转换与行动
  • 【PDF】使用Adobe Acrobat dc添加水印和加密
  • 安徽省委副秘书长、省委政研室主任余三元调任省社科院院长
  • 缺字危机:一本书背后有多少“不存在”的汉字?
  • 多家中小银行存款利率迈入“1时代”
  • 挖掘机4月销量同比增17.6%,出口增幅创近两年新高
  • 【社论】人工智能将为教育带来什么
  • 泽连斯基:乌克兰已做好与俄罗斯举行会谈的准备