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

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 &//注意这里还有& 不要忘记了。

http://www.xdnf.cn/news/5273.html

相关文章:

  • 三维空间中的组织行为映射:MATLAB 数据插值可视化技术
  • 【网络】:传输层协议 —— UDP、TCP协议
  • 兔子队列?RabbitMQ详解(1)
  • 数字化转型-4A架构之技术架构
  • Mac下Robotframework + Python3环境搭建
  • 《智能网联汽车 自动驾驶系统设计运行条件》 GB/T 45312-2025——解读
  • 无锁秒杀系统设计:基于Java的高效实现
  • 补补表面粗糙度的相关知识(一)
  • leetcode 15. 三数之和
  • Java 原生异步编程与Spring 异步编程 详解
  • 比亚迪全栈自研生态的底层逻辑
  • MySQL 索引(二)
  • 服务器mysql连接我碰到的错误
  • 高斯过程回归(GPR)原理的通俗解释
  • Spring循环依赖问题
  • 【DLF】基于语言的多模态情感分析
  • 邮件群发中如何确保图片加载速度
  • Qt开发经验 --- 避坑指南(12)
  • vue配置代理解决前端跨域的问题
  • python环境搭建和pycharm的安装配置以及使用face_recognition与cv2
  • 一键智能AI抠图,释放创意无限可能
  • 自定义类型:结构体进阶
  • CANopen转Profinet网关,AGV可以无缝地与工厂的控制系统集成
  • Js 判断浏览器cookie 是否启用
  • C/C++复习--最易懂的C语言分支与循环语句--详解
  • 卫星导航算法程序设计——单点定位测速(SPV)
  • C语言_函数hook方案
  • Java学习手册:Spring Cloud 组件详解
  • 8.3.监控与日志体系
  • LAMMPS分子动力学基于周期扰动法的黏度计算