Document how to deploy the project to your own server

introduction

After the project is developed, everyone wants to be able to access it, so we can deploy it on the server, whether it is the front end or the back end, we can deploy it

  • First of all, we need a server, whether it is a local or a cloud server (Alibaba Cloud, Tencent Cloud, etc.). If we use a cloud server, we can access our developed projects anytime and anywhere.
  • So let's get down to business: let's start deploying the front-end project first
  • Use the next ruoyi to achieve the next deployment

Deployment of front-end projects

1. Package the front-end project

  • Option One:
  • 1. Put the front-end codePack it into zip and upload it to the server
  • 2. Unzip
unzip xxx.zip
  • 3. Install the npm image dependency [because if the server does not have an npm environment at this time]
npm install --unsafe-perm --registry=https://registry.npm.taobao.org
  • 4. Carry out the packaging operation of the project
npm run build:prod
  • 4. Enter the dist directory to view your packaged
cd /dist
# 查看此时dist目录位置,使用pwd
root/worksapce/ruoyi-ui/dist

Scenario 2:

  • After packaging the dist, upload it to the server

2. Deploy dist with Nginx

  • After writing down the dist directory, switch to nginx.conf in the nginx directory
  • Modify the location

After configuring nginx, you can access it from the external network

# 这里本地使用集群才配置,单台可以忽悠
upstream ruoyi{
    
    
	server 192.168.31.101:8080 weight = 5;
	server 192.168.31.102:8080 weight = 3;
}
location /{
    
    
	root /root/workspace/ruoyi-ui/dist;
	index index.html index.htm;
}
# 配置对应的信息
location /prod-api/ {
    
    
	proxy_set_header Host $http_host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header REMOTE-HOST $remote_addr;
	proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
	proxy_pass http://ruoyi/;
}
  • After configuration, execute the following command
# 检查nginx.conf配置是否正确
nginx -t
# 重启nginx
nginx -s reload

Deployment of backend projects

  • Packed into a jar package

  • Packed into a war package

    • 1. Open ** pom.xml** to view the packaging method (the packaging method selected when creating the project)
    • 2. Add a dependency to pom.xml
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>
  • 3. Add a startup class

public class SpringBootStartApplication extends SpringBootServletInitializer {
    
    
 
 @Override
 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    
    
                                 //Application的类名
     return application.sources(RuoYiApplication.class);
 }
 
}
  • 4. The project is packaged into a package;
  • 5. Start the backend:nohub java -jar ruoyi.jar &

end

At this point, the deployment is basically completed. The backend is very simple. You can change the database and Redis, then package it into a jar package, and the command to start the backend directly is complete.

Guess you like

Origin blog.csdn.net/weixin_59823583/article/details/130255045