foreword
Before uploading, you need to have a project that has been built and separated from the front and back ends. The following is the project structure diagram of the back-end and the front-end page diagram
Configure a new container on the server using the prepared docker image
create container
The OS of the docker image used here is ubuntu20.04. You need to bring it yourself.
Pay attention to port mapping: Usually the port numbers used by front-end projects are generally 80 and 443 ports. Here, because there is no plan to issue ssl certificates and filings, it is just a record operation, so port 443 is configured. The port configured for the backend project I use here is port 4000. At the same time, configure a port mapping to port 22 for ssh login.
Once the port mapping here is determined, it will be difficult to change it later.
Use the following statement to create (note that the 20001, 4000, and 81 ports used here must be released by the server console firewall, and will not be demonstrated here)
docker run -p 20001:22 -p 81:80 -p 4000:4000 --name chat_server -itd docker_lesson:1.0
After the creation is successful, use the following statement to see that a new container is running
docker ps -a
Use the following statement to enter the container and set the container password
docker attach my_docker_server # 进入创建的docker容器
passwd # 设置root密码
Configure the ssh login of the container
ssh [email protected] -p 20000 # 将xxx.xxx.xxx.xxx替换成自己租的服务器的IP地址
Use the following statement to configure password-free login
ssh-copy-id host (ssh配置文件里面host值)
Upload ancestral files, (acwing users only)
scp .bashrc .tmux.conf .vimrc Host名:
Download tmux, and after downloading, you can use the ancestral files.
apt-get update (进行任何下载操作前都要更新一下先)
apt-get install tmux
Download Nginx
It is in the following article.
Nginx—Installation and use on ubuntu system of linux
When closing the naignx service in the container, it will also shut down the nginx outside the container, so be careful.
After downloading, run it and you should be able to access the following page through the server IP+port.
Install and configure mysql and jdk
install mysql
sudo apt-get install mysql-server
Start the MySQL service
sudo /etc/init.d/mysql start
sudo service mysql start
Set the password for the root user:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
Log in again (the user name and password in the project configuration file should correspond to this)
mysql -uroot -p123456
Install JDK (this corresponds to the JDK version of the backend project)
sudo apt-get install openjdk-8-jdk
Prepare the database and corresponding tables (to be consistent with local debugging)
In the idea, click the database on the right and right click on the corresponding table to get the table creation statement as shown below
Then create a new sql suffix file in the container to store the copied sql statement
Then the sql file inside is used to create a table
Here you must first create it under the corresponding database
source /root/create_table.sql;
Upload the backend project and run
Package and upload the jar package
First of all, the back-end project must be packaged first, click on the package on the right
After the packaging is completed, there will be an additional target folder, and there will be a jar package in it.
Upload to the container through git_bash (provided that ssh login has been configured)
scp backbound-0.0.1-SNAPSHOT.jar 1server_chat:
Use the following command to transfer the jar package under the root directory to the created folder
cp ~/*.jar .
Run the jar package
Open a tmux window to run the jar package
java -jar backbound-0.0.1-SNAPSHOT.jar
Run front-end project tests locally
There is also data in the server database, but it is full of question marks (doesn't matter)
Upload the front-end project file
Package the front-end files, click bulid directly, and then a dist folder will appear
Use gitbash to upload dist to the corresponding folder of the server
scp -r dist 1server_chat:chat/web/
Then you can configure nginx orientation, and everything is the same as taught in the blog below.
Nginx—Installation and use on ubuntu system of linux
Finally, you can use ip+port to access
The following article here solves the problem that has troubled me for a long time. Every time the port 80 of nginx is changed, 404 is reported. Use the following method to solve it.
There may be two solutions for the 403 error reported here. One is to change the working user of nginx to the root user, and the other is to grant permissions to the web directory. The latter is usually used.
This time, it is solved by granting 777 permissions to the root directory.
Operation and maintenance troubleshooting | 403 errors occur when accessing nginx- Know about
nginx 80 port configuration multiple locations invalid access 404