当前位置:网站首页>Project deployment (simplified version)

Project deployment (simplified version)

2022-07-23 11:05:00 Qingchi

  Deployment of front-end projects , And deployment of backend projects

 

Front end deployment server : Nginx

Back end deployment server : Tomcat( Embedded )

  On the server A(192.168.*.*) Install in Nginx, Upload the front-end packaged files to Nginx Of html Under the table of contents

modify Nginx The configuration file nginx.conf

take nginx.conf In profile , Put the original monitor 80, 82, 8080 Port number Comment out the virtual host of , Introduce the following configuration information :

server {
        listen       80;
        server_name  localhost;

        location / {
            root    Own page ;
            index   Page name .html;
        }
		
		location ^~ /api/ {
			rewrite ^/api/(.*)$ /$1 break;
			proxy_pass http://192.168.*.*:8080;
		}
		
        location = /50x.html {
            root   html;
        }
    }

adopt nginx Visit front end Engineering

192.168.*.*

Reverse agent configuration

After the deployment of front-end engineering , We can normally access the login page of the system , Click the login button , You can see the request initiated by the server

/api This prefix passes without modifying the server code nginx Can easily solve this problem

This configuration represents , If the request is currently nginx, And if the requested path is /api/ start , Will be location Handle . And location in , Two pieces of information are mainly configured : rewrite(url rewrite ) and proxy_pass( Reverse proxy ). Next, let's analyze the configuration of these two items .

rewrite ^/api/(.*)$ /$1 break;

Here is a regular expression , If the request path is /api/ start , The following request path is arbitrary , The original url The path is rewritten as /$1, there $1 It refers to wildcards .* The content of this piece . such as :

/api/employee/login ------> ^/api/(.*)$ -------->
  here  (.*)  The match is  employee/login ------> 
 Finally rewritten as /$1 : /employee/login

Reverse proxy

proxy_pass http://192.168.138.101:8080;

On the server B(192.168.*.*1) Install in jdk、git、maven、MySQL, Use git clone The order will git Clone the code from the remote warehouse

confirm jdk: java -version

confirm git:git -version

confirm maven:mvn -v

Push the developed code to the remote warehouse , And on the server B Clone it from

# establish java Code storage directory 
mkdir -p /usr/local/javaapp

# Toggle directory 
cd /usr/local/javaapp

# Cloning code  ,  You need to use your own remote warehouse 
git clone https://gitee.com/**/***.git 

We can go through ps -ef|grep java Instructions , Check whether the service is started .

Execute the script

#!/bin/sh
echo =================================
echo   The automated deployment script starts 
echo =================================

echo  Stop the original running project 
APP_NAME=**********

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 2
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

echo  Ready to go from Git The warehouse pulls the latest code 
cd /usr/local/javaapp/*****

echo  Start from Git The warehouse pulls the latest code 
git pull
echo  Code pull complete 

echo  Start packing 
output=`mvn clean package -Dmaven.test.skip=true`

cd target

echo  Start project 
nohup java -jar *********.jar &> *****.log &
echo  Project start up complete 

Picture display problem handling

Modify the file storage directory :path: /usr/local/img/

Put the local test image folder img( Whole folder ) Upload to server B Of /usr/local Under the table of contents

Then you can access the address of the main database and come out successfully

原网站

版权声明
本文为[Qingchi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230537007900.html